openSockets strangeness
Alex Tweedly
alex at tweedly.net
Sun Oct 12 19:20:49 EDT 2008
Russell Martin wrote:
> Hi. I've been playing around with sockets. I'm attempting to create a stack than can run shell commands on OS X so that I can get a multi-threaded effect.
>
> I've never used sockets before, so after, digging through the chat example stack, I dug right in.
>
> I'm finding some odd behavior that I'm hoping someone out there can shed some light on.
>
> Question #2:
> ============
> If my listening stack is open and the connection is made, then while the connection is up, calling the openSockets funtion returns 3 lines such as the following:
> 10261
> 127.0.0.1:10261
> 127.0.0.1:57219
>
> Does anyone have any idea why it isn't simply:
> 127.0.0.1:10261
>
> What are those 10261 and 127.0.0.1:57xxx lines all about? Does the IDE use that 57xxx (I've noticed that it is so far in the 57000 range) for it's own purposes?
>
>
This is basically because you are running both the listener (or
'server') stack and the other one within the IDE, so you have a single
set of sockets for all running stacks. This can be confusing (and can be
downright annoying, if for instance one of your stack does a resetAll
it will close all the sockets). I found it useful to either use two
machines, or to build a standalone for one of the stacks, and run the
other within the IDE (or you may be able to run both Rev and MC IDEs at
same time to gt the same benefit).
So that's why you see both 10261 (one stack has done an 'accept' on this
port) and 120.0.0.1:10261 (the other stack has done a copnnect on this).
The third open socket (127.0.0.1:57219) has been opened for you by the
'accept' command, and is the socket identifier you would use to
communicate from the listener back to the other process. See the
Dictionary on the 'accept' command, specifically
> Comments:
>
> When a connection is made or a datagram is received, the accept
> command creates a new socket that can be used to communicate with the
> other system (or process).
-- Alex.
More information about the use-livecode
mailing list