TCPSocket Question

Hi,

What do you suggest as a best practice for using the SocketCore.Purge method?

Since this removes all data from my socket’s internal receive buffer would I want to issue this at the end of my transmissions or do this after every iteration of “Readall” (DataAvailable)?

Thanks in advance!

I would say “don’t use it”. It literally tosses away any data you have in the receive buffer, which is already done for you by ReadAll.

Cool thanks Joe I appreciate the response.

[quote=25305:@Mike Cotrone]Hi,

What do you suggest as a best practice for using the SocketCore.Purge method?

Since this removes all data from my socket’s internal receive buffer would I want to issue this at the end of my transmissions or do this after every iteration of “Readall” (DataAvailable)?

Thanks in advance![/quote]You don’t need to “purge” the socket in anyway after reading.

On the OS level you actually pass a pointer to a block of memory for which the OS will “copy” the contents into, and at that point your application has the only copy of that data - the socket on the OS level only has what was left over (if you didn’t read it all) or new packets that came in afterwards.

Xojo obviously manages the passing of a pointer /memory management for you, you just worry about how much you want to read at a time.

between a data available event (or a manual poll), you will only be able to read the number of bytes that are available - if you didn’t read it all, then there will be bytes left on the socket’s buffer to which purge will be applicable for.

It’s only useful if you only need say 500bytes of a 1000byte transmission, but being a stream-based transmission you can’t ensure a specific number of bytes being in the buffer during your routine, so it has a very narrow applicable use.

I’m not sure if the OS actually provides a “purge” mechanism, so it’s very likely to be a readall to a random memory location which is then instantly removed.

Thanks Tony I appreciate the info.

my .2c…
Do you consider the data to be delivered when the last byte of the packet is received or after the last byte of the packet has been sent?