Progress on preventing multiple instances of a program from running in windows
thierry
douez at wanadoo.fr
Fri Dec 3 05:52:23 EST 2004
Hi,
LJ> Hello... the following script seems to work.
LJ> Factors to consider:
LJ> 1)The stack should be set to purge itself from memory upon closing
LJ> 2)Some firewalls might prevent the program from accepting
LJ> connections on a port
LJ> 3)This prevents multiple instances, but still does not quite allow
LJ> the two instances to communicate. Writing to a socket from one instance
LJ> seems to steal the ability of the other instance to listen to that
LJ> socket - I am still trying to work out how to do that.
humm, with my little experience, you probably need to differenciate the 1st
instance from the second. if the first do a accept connection ( Server mode )
the second instance should do a connect as a client. So, if you see yourself
in the netstat result then run a open socket on the port.
LJ> 4)You might want to consider hiding the windows console and
LJ> setting the cursor to watch while the script performs the shell command.
LJ> 5)This will not work with the opensockets function, because that
LJ> does not return the sockets opened by the other instance. The shell
LJ> command for this works quite well (at least on my computer).
LJ> Cheers,
LJ> Jonathan
LJ> on preopenstack
LJ> get shell("netstat -a")
LJ> put it into OPS
LJ> put the number of lines in OPS into Z
LJ> set the itemdelimiter to ":"
LJ> repeat with X = 1 to Z
LJ> put word 2 of line X of OPS into WPS
LJ> if item 2 of WPS = "48953" then put "open" into queryold
LJ> end repeat
LJ> if queryold = "open" then
LJ> answer "This program is already running, do you wish to run another
LJ> instance of it?" with "No" and "Yes"
LJ> put it into AAA
LJ> if AAA = "No" then
LJ> close this stack
LJ> end if
LJ> else
LJ> accept connections on port 48953 with message "queryinstance"
LJ> end if
LJ> end preopenstack
Running get shell("netstat -a") , i got this on a Win98 box :
Active Connections
Proto Local Address Foreign Address State
TCP xxxxx:1068 0.0.0.0:0 LISTENING
TCP xxxxx:2530 0.0.0.0:0 LISTENING
TCP xxxxx:1068 127.0.0.1:2530 ESTABLISHED
TCP xxxxx:2530 127.0.0.1:1068 ESTABLISHED
what i don't understand is that i do only one <accept connection>,
and then only one external process read the socket. So, why this
4 lines ?
Regards, thierry
More information about the use-livecode
mailing list