Progress on preventing multiple instances of a program from running in windows

Alex Tweedly alex at
Fri Dec 3 13:18:30 EST 2004

At 12:59 03/12/2004 -0500, Lynch, Jonathan wrote:

>The fact that, on my windows XP computer, Rev is automatically setting
>itself up to listen to a port to which it just wrote a message seems
>awfully odd.
>My understanding of ports and sockets is weak - but shouldn't it be able
>to write to socket "" without setting itself up as
>listening to port 48953?

Yes, it should (and can - as verified by the echo server I sent earlier ....)

Your previous email implied something slightly different from what you say 
here or at least, I read it slightly differently ...)

You said then (my emphasis)

>What was happening was that BOTH INSTANCES WERE SET TO LISTEN to that
>port, but once the port was read by one instance, it was not read by the
>The solution is like this:
>Open socket to ""
>Write "QueryInstance" to socket ""
>Close socket ""
>Close socket "48953"

I think what you are seeing is some variant of the re-use socket problem. 
Because Rev is telling the OS to re-use the same socket address, things are 
acting a bit screwy.

I can't exactly explain what you're seeing - but I'm pretty sure there's 
something about reusing sockets behind it.  If you want to send a more 
complete code fragment, I can give it a try - but I suspect that port 
re-use will catch us out one way or another.

Note that my long post earlier (which first tried to open the port - and if 
that failed, only then went into server mode and did an Accept)  avoids the 
re-use issue completely, and should work on any OS.

>Is there a shell command for writing to a socket that could be used that
>might not have this behavior?

Nothing very convenient.

>My method of closing port 48953 after writing to "" (and
>doing the same with port 48954 for communicating in the reverse
>direction) works to allow two instances of a stack, running under two
>different instances of Rev, to communicate with each other - however,
>when I save the same stack as a standalone and try it with two instances
>of that standalone, they only manage to pass a couple messages before
>getting confused.

It's also quite inefficient (opening and closing ports). I wonder if it may 
be running into problems with Time-Wait (ports that are closed are put into 
a temporary time-wait state to avoid problems of late packet arrival - and 
that can cause problems when you are rapidly binding and closing the same 

>If it were possible to write to socket without trying to steal the
>listening of that stack, it would be much easier.

Try the long code fragment I sent - I'm pretty sure it will work generally, 
and it definitely is OK on Windows (2000 and I also tested it on XP under 
Dreamcard Player).

-- Alex.

More information about the use-livecode mailing list