Winanjaya Posted September 16, 2003 Posted September 16, 2003 Dear the Expert, I am very new in VB.NET, I created winsock app by following the .NET sample program .. what I do not understand is why the TCPListener seems like does not automatically read when the new string sent by TCPClient..? .. I mean for the 1st time connected TCPListener works fine ..but after that I tried to send some strings to it but it seems like unable to read.. does it have read event to handle it ..(like winsock component in VB6?) please help me ..I have stuck on this for almost 2 weeks ..and I am getting frustated with this..;>(( many thanks in advance Regards Winanjaya Quote
Administrators PlausiblyDamp Posted September 16, 2003 Administrators Posted September 16, 2003 Post some code if possible, makes it easier for people to see where you're comming from. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Winanjaya Posted September 16, 2003 Author Posted September 16, 2003 Thanks for your quick reply, I followed the codes at microsoft.com private sub form_load() tcpListener.Start() ListenerGO end sub private sub ListenerGO() Console.WriteLine("TCP Server is up and waiting for Client connection...") Try ''Accept the pending client connection and return a TcpClient for communication. Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient() Console.WriteLine("Connection accepted.") ' Get the data stream. Dim networkStream As NetworkStream = tcpClient.GetStream() ' Read the data stream into a byte array. Dim bytes(tcpClient.ReceiveBufferSize) As Byte networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) ' Return the data received from the client to the console. Dim clientdata As String = Encoding.ASCII.GetString(bytes) Console.WriteLine(("Client sent: " + clientdata)) Dim responseString As String = "Successfully connected to TCP server." Dim sendBytes As [byte]() = Encoding.ASCII.GetBytes(responseString) networkStream.Write(sendBytes, 0, sendBytes.Length) Console.WriteLine(("Message Sent by TCP Server /> : " + responseString)) 'Close TcpListener and TcpClient. tcpClient.Close() tcpListener.Stop() Console.WriteLine("Exit") Console.ReadLine() Catch e As Exception Console.WriteLine(e.ToString()) Console.ReadLine() End Try End sub am I missing something?? TIA Winan Quote
Administrators PlausiblyDamp Posted September 16, 2003 Administrators Posted September 16, 2003 Not worked with the TCPListner overly much so I may be wrong - but won't the tcpListner.Stop prevent it having new connections? Try removing that line and just keep looping in the main form just to see if it will keep accepting new connections. private sub form_load() tcpListener.Start() do ListenerGO loop while true end sub if it now starts to accept more than one connection then at least the problem is spotted ;) (even if the code I suggested isn't that good) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Winanjaya Posted September 16, 2003 Author Posted September 16, 2003 I am afraid that it will do looping forever that mean my PC will hang .. does VB.NET also provide doevent ..for exit ... I need your idea .. thanks again Winan Quote
AndreRyan Posted September 17, 2003 Posted September 17, 2003 Application.DoEvents() Private IsClosing As Boolean Private Sub form_load(sender as object, e as eventargs) Handles MyBase.Load tcpListener.Start() Do ListenerGO Application.DoEvents() Loop While IsClosing = False End Sub Private Sub Form_Closing(sender as object, e as EventArgs) Handles MyBase.Closing IsClosing = True End Sub Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.