My Xojo WebSocket chat client receives server handshake headers; and then I do a .ReadAll to grab them (inside DataAvailable event) …
… thereafter, as expected, the Socket receives text messages from server on a regular basis; for this, I am doing a .ReadAll inside DataAvailable event
a) Is it Okay to do it this way ?
It is 100% working so far, but is so bloody fast that there is need no control whenever the received message is complete or not …
b) What if meanwhile there is another message being sent from server, and the previous one is still being downloaded? is there any DataAvailable queue list and the DataAvailable event being fired individually for each one ?
It is expected and I am concerned with high traffic periods.
c) Is it important to call Socket.Purge ? How often ?
TCP communication is a stream, not individual messages. You must impose some protocol on the stream to distinguish each individual message. In any given DataAvailable event, ReadAll could return a single message, part of a message, more than one message, the end of one message and the start of another message, etc., etc. Devise a protocol to give form to the stream of information. The fact that you are currently seeing one message per event is due to the timing of the messages. It is not guaranteed.
You shouldn’t have to Purge - you would lose data if you do. But you might Flush on the sending end if you’re sending short, discrete messages rapidly. Otherwise, they might get buffered up into a larger packet and sent all at once. I’ve not run into a need, but depending on the nature of your communication, it might smooth things out if you notice them getting “bunchy”.