> strictly through the protocol implementation) how can I force WSocket's > OnDataAvailable event to queue the data until it's assembled into one > large > chunk so i can then process it as if it all arrived that way instead of > split up.
TWSocket will do that for you in the case where your chunks are delimited at the end. It is called "Line Mode" in TWSocket but is not at all limited to text lines. A line is simply defined by an unspecified number of bytes and a delimiter also made of an unlimited number of bytes. By default, LineMode is FALSE and LineEnd is #13#10. You may turn LineMode to TRUE and change LineEnd to whatever you selected as delimiter (single or mulitple bytes). Once LineMode is TRUE, the component will assemble data and trigger OnDataAvailable for each chunk received, no matter how it is split or merged into packets. > method you would recommend to force the socket to wait until the rest of > the > data comes in? Using TWSocket, younever wait. TWsocket is an asynchronous component. You don't wait for something, you just do nothing and when something happend, such as data ready to be received, you get an event. From the event handler, you do whatever is needed depending on the event. For example, when you opened a TCP connection, each time data is comming in, you get an OnDataAvailable event. In the handler, you call TWSocket.Receive to transfer the data into your own buffer for processing. Since packets are not related to your application content, you must be sure to have received enough data before processing. So you just append data to your buffer and start processing only when you have enough data to process as a whole. -- Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] http://www.overbyte.be ----- Original Message ----- From: <[EMAIL PROTECTED]> To: <twsocket@elists.org> Sent: Saturday, December 17, 2005 9:05 AM Subject: [twsocket] socket programming tcp/udp primer question >I recently read the tcp/udp primer under the overbyte.be "support" section > and the tcp data fragmented packet example using the text string "Hello" > caught my attention because that is something i always wondered about in > socket programs. The fact that the data can be split up into multiple > packets coming in fragments like "he" "l" "lo" is something i'd like to > know > how to handle properly. What i mean by this is if i'm expecting the line > "hello" and i'm parsing TCP receive socket data i need to handle "hello" > as > a whole word without the fragmentation causing my parser to fail and pass > the data on without proper handling. I'm wanting to write a chat client > for > icq/aim/irc/yahoo or any other major protocol and none of the protocols > have > set boundaries that are apparent to me. Some end on a series of NUL chars > (#0) in Delphi or a numeric (a given number) and so on... I'm pretty new > to > sockets and i need some advice from the more experienced users which would > be you guys. If i'm expecting a 2 KB packet char for char that's using TCP > protocol and is guaranteed always to be there no exceptions (enforced > strictly through the protocol implementation) how can I force WSocket's > OnDataAvailable event to queue the data until it's assembled into one > large > chunk so i can then process it as if it all arrived that way instead of > split up. I'm aware that I will have to set my own boundaries on the > begining of the expected data and the end of the packet data so that i can > get the big picture and make sure i process it as I need but is there any > method you would recommend to force the socket to wait until the rest of > the > data comes in? Would calling wait() and peeking the data not help at all > or > would the buffer be overwritten during the wait period instead of > concatenated with the data coming in afterwards? Can i see an example by > chance or get a professional opinion. > > -Brad > -- > 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 -- 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