realbasic-nug
[Top] [All Lists]

Re: TCP transmissions

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: TCP transmissions
From: Brian Rathbone <brianrathbone at bellsouth dot net>
Date: Thu, 27 Apr 2006 22:33:23 -0400
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20060428004201 dot 0B1EF731AA at hoggle dot dreamhost dot com> <8CD3029F-42E0-4323-A235-A803FA258DC4 at kellerfarm dot com> <acc0f28d93b8bcee7e155fe489210f95 at realsoftware dot com> <BC936F8B-04B7-4E6E-8B41-34749CD97BAC at kellerfarm dot com>


andrew at kellerfarm dot com wrote:

Do you mean that you could have pieces of multiple transmissions in the same DataAvailable event? How would you tell them apart?


You will still get the data in the same sequence that you wrote it, but you may have more than one seperator available in the datavailable event.

So let's say you do:

socket.write("Hello") + seperator
socket.write("World") + seperator
socket.write("It's me!) + seperator

You might get:

Hello + seperator + World + seperator + It's

and then in the next fire of the event you might get:

me! + seperator

So you need to loop through the available data and look for seperators. For each seperator you find, you have the end of one message. If you get an incomplete message, you can choose to leave it in the buffer until the next fire. It may look something like this:

 i = instr(me.lookahead,seperator)
 while i > 0
   if i > 0 then
     s = me.read(i)
     //s now has a complete message + seperator
   end if
   i = instr(me.lookahead,seperator)
 wend

hth,

Brian
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


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