realbasic-nug
[Top] [All Lists]

Re: TCP packet - are separate packets collected into one?

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: TCP packet - are separate packets collected into one?
From: Brian Rathbone <brianrathbone@bellsouth.net>
Date: Thu, 26 Feb 2009 16:56:23 -0500
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <49A70E35.1090504@bellsouth.net>
References: <89fe53800902261201u4d7703d7s5a7f9edeab9bad45@mail.gmail.com> <49A70E35.1090504@bellsouth.net>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
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>


<Prev in Thread] Current Thread [Next in Thread>