Hello Wes, In addition to the advice of Francois is what I often do if designing a protocol that is both ascii data (for commands) and binary data packets, is to preceide the packet with a length in hexadecimal form (byte, word or dword). Wy ? Because if most of the data is ascii command then it make the readability better if you log the data for debugging purposes.
--- Rgds, Wilfried http://www.mestdagh.biz Thursday, June 2, 2005, 12:37, Francois Piette wrote: >> It's easy with LineMode on - ICS only forwards the data on when it >> receives a delimeter. But when it's off, it seems as though anything >> other than file sends and receives (because you don't really act on the >> file stream, you just send or recieve its bytes) proves to be a >> difficult task. > If not using a delimiter, you must use a byte count. In any case, > the receiver need to know how much > data has been sent by the sender. TCP doesn't preserve boundaries: it send > all data in the correct > order, without error and only once. But it can split or merge data according > to what is needed by > the network layer. > Most protocols use line mode (SMTP, POP3, NNTP, ...) some use both : FTP and > HTTP. FTP use two TCP > connections: one for commands and one for data. On command stream, it use > line mode. On data stream, > it just send data. End of data is found because the stream is > simply closed. HTTP use a single TCP > stream, begin with line mode in his header and then switch to byte count for > the document. Byte > count is given in one of the header lines. > So what do you have to do ? You have to design your own protocol, using line > mode or not, it is not > very important. What is important is that at any moment one side know what > the other is trying to > do. > I understood that you don't want to use line mode. Perfect for me. Use a byte > count. You can, for > example build each of your message with 4 byte being a 32 bit > integer that gives the number of data > bytes that follow. Send is trivial. Receiving require a buffer where you > append everything you > receive. Each time you received something (OnDataAvailable event, then call > Receive method), you > check how many bytes you have received. If less than 4, you just do nothing > more. If more than 4, > then you received your count. You compare the count with the actual data > received. If you have > enough data, you trigger your own event, such as OnMessageReceived, passing > the count of bytes and > the pointer to the first byte into your buffer (You can also copy the data > but if will be slower). > When the event handler returns, you remove the count and the > message data from the buffer, keeping > the rest for the next round. > -- > [EMAIL PROTECTED] > http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be