tags:

views:

328

answers:

1

My tcp client has made a connection to the server script! Now that it has connected, how can it send a simple string? I do not know what any of the overloads for the .Client.Send method even mean, or how to use them. I already have a system set up on the server side to parse the string when it is received on the server side, but I have no idea how to send a simple string to it.

Thanks for the help!

This is in vb.net by the way.

+1  A: 

This article should point you in the right direction :)

Chris Thompson
Any way to do it without streamwriters or whatever they are called? Is there any simple way to send a string, preferable in one line of code?
Cyclone
I made a streamwriter, which writes to the tcpclient stream, but nothing is showing up on the serverside.
Cyclone
You need to get the bytes of the string, which can be done to the Encoding.ASCII.GetBytes() method and write it to the stream with networkStream.Write(sendBytes, 0, sendBytes.Length)
Chris Thompson
Okay. Now I am having connection issues however, would Dim srv As TcpListener = New TcpListener(9999) work? When the client tries to connect, it recieves a big ol' error.
Cyclone
It connects now, and it does work, but here is my issue: While the server waits for a response from the client, it cannot do anything, at all, and the client is totally useless since it always sends. How can I make the server ALWAYS listen, without lagging? The client I can fix by rigging it up to my UI.
Cyclone
You will need to code the server to spawn a new thread to handle the connection and then put the server in an infinite loop that waits for connections, spawns a thread, and returns to waiting for a connection. So, you will need to spawn a thread and pass it the object returned from this line (from the link above) Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient(). That thread will handle anything that needs to be done with that specific connection
Chris Thompson
Okay, thanks!
Cyclone