Socket Comm Followup - A couple of questions

Brian Yennie briany at qldlearning.com
Sat Apr 16 00:09:35 EDT 2005


> Thanks, Brian... that makes more sense. Or I would assume some
> mutually-agreed-upon termination character could work as well, right?

Yup. Technically, the length method is slightly more efficient (because 
it doesn't need to check each character coming in), but unless you're 
really squeaking performance I'd say go with what works for you.

> So would that mean that you could write to 
> "ftp.example.org:21|sendFiles",
> right? And if you wanted to open another socket, you could do so to
> "ftp.example.org:21|anotherSocket" and write to
> "ftp.example.org:21|anotherSocket"?

Yup. I think in the last docs that I saw on this, the example was just 
with a numeral.

For example, if you wanted to be able to open as many connections as 
you wanted to any server without worrying about trying to open the same 
socket twice, you could write a wrapper like:

function openSocket s
   global gSocketCounter
   if (gSocketCounter is empty) then put 1 into gSocketCounter
   else add 1 to gSocketCounter
   put (s&"|"&gSocketCounter) into tSocket
   open socket to tSocket
   return tSocket
end openSocket

Then it would open sequential sockets, like:
"ftp.example.org:21|1"
"ftp.example.org:21|2"
"ftp.example.org:21|3"

Of course if you had specific tasks for each socket, the more verbose 
names might be useful for debugging.

Note that you can't open more than one listener on the same port- you 
can just make more than one connection to a remote host. Sort of a 
one-server-to-many-clients relationship.

HTH
- Brian



More information about the use-livecode mailing list