Jump to content
  • Advertisement
Sign in to follow this  
Gorgoo

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

This topic is 4159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!