TCPSocket questions

Hi all,

If I have successfully established a TCP Connection between server and client, Server sends a new Datapackage

TCP splits the packe in e.g. 3 subpackages and client receives them.

When does TCPSocket.DataAvailable fire?

After each Subpackage has been received or only once after all packages are received?

Thanks

Stefan

After each subpackage has been received. Ie., you get 3 DataAvailable events. It’s up to you to detect a complete packet.

How do I know how many packages are send?

That is a question that lies above the transport layer. You must construct your messages such that you can tell when you have a complete transmission. This is usually achieved by either transmitting the expected number of characters as a separate part of the protocol, or by appending a delimiter that signals the end of the string.

Thanks,

That is what I’ve feared…

… but is manageable :slight_smile:

One additional question.

The message comes in a xml like structure with beginn operator. + content + end operator

So I could easily check if I have received the message.

However it might be possible, that the message received contains n - begin / end operator in one message.

In Dataavailable Event I would readall data available, attach received data to a separate string and purge . NExt event i would do the same (read all, append to string and purge.

Each time I would check string for begin / end operator received and do my stuff. This way I could start processing the received message starting with the first begin/end sequence although the second has not been received completely.

Does it makes sense?

Or would it be better to implement a “endmessage” operator and wait until it has been received.

The server application already exists and the protocol is already in place … (but could perhaps ask for changes :slight_smile:

You can whatever you define.

I’m using Json for sending data around (Json-RPC from Kem Tekinay). This worked nicely for small amounts of data.