2012/2/4 Bernd <prof7...@googlemail.com>: > You need a robust way to determine how long your > protocol message is, at which byte exactly it ends and the next > message begins.
The simplest way would probably be if you prepend all your messages with a length field and a checksum field to be sent as the very first bytes of each of your custom protocol messages (also take care of endianness and exactly specify this in your protocol description). Then you can either read as many bytes are available on the stream (if it is less than still needed) or read only as many bytes as are still missing (if equal or more are available), leave the rest of the data in the stream, process the message and trigger the read event again to read what can only be the beginning of the next message. You can also use lNet in blocking mode (which can sometimes make things easier) simply by specifying a timeout value for the socket. Then you can just have a thread looping and trying to read indefinitely, counting received bytes and let it generate your own events on completion of a message instead of using the lNet events which fire on every TCP packet. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal