I suppose the example below would be clearer with this example:
Let's say you did 2 writes to your socket like, and for the sake of
example that you are using ! as your command terminator:
me.write "TEST MESSAGE!"
me.write "SECOND MESSAGE!"
In a single firing on the dataavailable event on the receiving socket,
you might get:
TEST MESSAGE!SECOND MESSAGE!
or you might get
TEST MESS on the first firing of dataavailable
and AGE!SECOND MESS on the second firing
and AGE! on the third.
You need to account for all eventualities.
Brian Rathbone wrote:
For protocols that use a CRLF (or other character) terminated command,
I usually use instr and lookahead to check for CRLF, and then loop
through the data and parse out individual commands while ignoring any
partial commands. It looks something like this:
i = instr(me.lookahead,terminator)
while i > 0
'//read data up to i from socket
'//parse out command and do stuff
'//since we read data up to i, lookahead is only looking at data
left in the buffer
'//look for another terminator
i = instr(me.lookahead,terminator)
wend
hope that makes good sense.
Brian Rathbone
<http://www.brianrathbone.com>
The Dawning of Power fantasy trilogy is now available through iTunes
for iPhone and iPod Touch
<http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=305606493&mt=8>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|