Sign in to follow this  
Gorgoo

[.net] Accepting Information Sent to TCPListener (in Visual Basic)

Recommended Posts

I'm making a program involving a chat between a server and client, and while I think I'm sending the data correctly, I don't know what to add to make the server accept it. The code to send the data is ===== 'ClientClass is the TCPClient If ClientClass.Connected = True Then Dim NetStream As NetworkStream = ClientClass.GetStream Dim strMessage As String = txtInput.Text Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage) NetStream.Write(sendBytes, 0, sendBytes.Length) End If ===== To accept the data, I put "ServerClass.Start" (ServerClass being the TCPListener) in the Form Load sub, and the following code in a timer tick sub. ===== If ServerClass.Pending = True Then ServerClass.AcceptTcpClient() End If ===== I'm assuming that the data is sent, and that I need to add some code to have it be recieved. However, I'm not sure what that is. I know this is kind of a long post, but basically I'm just asking if anyone knows what I need to add. I'm sure it's something simple, but I've looked, and can't find it. Thanks.

Share this post


Link to post
Share on other sites
Take a closer look at AcceptTcpClient, it is actually returning a TcpClient instance. You can use that instance to communicate with the client that connected, including recieving messages from it. The TcpListener is only used to accept connections from other clients, never to do the actual sending and receiving of messages.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this