TCPSocket Readall question

Hi,
I have a small app that remote controls software on another machine via a tcp/ip connection that is working for the most part. Now I am trying to clean up the rough edges so I can start adding more functions to it.

One auestion I have is regarding data received in the tcpsocket buffer. When you use the Readall method, does this then empty the tcp buffer or do I need to purge it after I read it and stuff it in my buffer and before I send another tcp/ip command out that port? In other words do I need to, in code make sure no data is left in the tcpsocket buffer before the next tcpsocket write so my parsing does not get confused.

buffer1=(TCPSocket1.ReadAll)

Basically this app when a command button is pushed, sends one tcp command, recieves data, then based on the recieved data sets a label to say no data or sends another command, receieves other data to be displayed, followed by sending a second data request, receieves other data and displays that in another label, then starts all over again. The first command works in a timer, it is the rest I am working my way through.

The ReadAll method will remove all data from the buffer.

From the docs:
“Use the Read method when you want to get a specific number of bytes (characters) from the buffer. If you want to get all the data in the buffer, use the ReadAll method. In both cases, the data returned from the buffer is removed from the buffer to make room for more incoming data.”

TCP/IP Communications

Thank you Darren, i had read other sourses and some how missed this portion.

You’re quite welcome. I read through documents multiple times because I know I’m not going to absorb it all the first time.

And, even then, I still miss stuff…

Just don’t assume you’ll get the entire message in a single DataAvailable event. You have to parse the data you get to determine if you have the entire message or if you need to wait for more (ie., just return and deal with the rest of the data the next time DataAvailable fires).