Socket Comm Followup - A couple of questions
Brian Yennie
briany at qldlearning.com
Fri Apr 15 23:49:54 EDT 2005
> 1) I noticed that in Alex's examples, after the "listener" gets the
> message
> fired off after the "accept" has been triggered, the "read from socket"
> command says "read from socket lSock until CR"... any reason to read
> only a
> line of data at a time? If I am sending over lots of data, what's the
> good/bad thing about reading it in all at once?
As far as I know, the only thing to look out for is reading until
empty. Myself, I gravitate towards reading one line first because a lot
of protocols send headers in the first few lines. Often times, the
contents of the first line(s) will determine how the remainder of the
communication proceeds. But if you just need the whole block of data, I
would say go ahead and read it- but make sure you either send the
length of the data or use some sort of termination sequence, i.e.
read from socket s for 1 line
put it into tLength
read from socket s for tLength
put it into tData
OR
read from socket s until (myTerminationSequence)
> 2) I noticed in the Rev docs under "open socket", there is a reference
> to an
> "ID" parameter that is "an optional connection name for the socket and
> can
> be any string", and has the example:
>
> open socket to "ftp.example.org:21|sendFiles"
>
> Has anyone used this? And if so (or if not), how *would* one use this?
> And
> does this form work with UDP as well as TCP?
You can use this to make multiple client connections. For example, to
download multiple files at the same time- as a browser or FTP program
might.
>
> 3) When should one use UDP vs TCP? What are the ads/disads of each?
I'll let someone else chime in here, I'm not well versed in UDP...
More information about the use-livecode
mailing list