Progress on preventing multiple instances of a programfromrunning in windows
Dar Scott
dsc at swcp.com
Fri Dec 3 16:16:41 EST 2004
On Dec 3, 2004, at 11:17 AM, Lynch, Jonathan wrote:
> What I am finding is that it is forcing the TCP listen without even
> using the accept command. The following script:
>
> Open socket to "127.0.0.1:48953"
> Write "Greetings" to socket "127.0.0.1:48953"
> Close socket "127.0.0.1:48953"
>
> Causes the instance that ran this script to start listening to port
> 48953. Shouldn't it only do that if the script actually uses the accept
> command?
Rev is helping you by not waiting around for the open.
I put a field and a button on a card with this script in the button:
on mouseUp
put empty into field "field"
open socket to "127.0.0.1:48953"
put "open result: " & the result & lf after field "field"
write "Greetings" to socket "127.0.0.1.48953"
put "write result: " & the result & lf after field "field"
put "openSockets(): " & lf & the openSockets & lf after field "field"
put "netstat report: " & lf & shell("netstat -a -p TCP") & lf after
field "field"
close socket "127.0.0.1:48953"
put "close result: " & the result & lf after field "field"
put "netstat report: " & lf & shell("netstat -a -p TCP") & lf after
field "field"
end mouseUp
This put this in the field (with the netstat reports cut out):
open result:
write result: socket is not open
openSockets():
127.0.0.1:48953
netstat report:
Active Connections
Proto Local Address Foreign Address State
[no 48953]
close result:
netstat report:
Active Connections
Proto Local Address Foreign Address State
[no 48953]
The open only starts the opening sequence. The socket is put into open
sockets tentatively. The write should wait for timeout or success or a
refusal. The above example gets the connection refusal and there is an
error in the write. The openSockets() still includes the socket even
after open fails, which I think is a bug. The close socket gets no
error, which I think is part of the same bug.
On my system I did not see any reference to 48953 in the netstat report.
You might want to add -n to the netstat command and stop it from
flashing a window on Windows.
I ran the same test on OS X and it worked the same except it
(correctly) got an error on the close.
Dar
****************************************
Dar Scott Consulting
http://www.swcp.com/dsc/
Programming Services
****************************************
More information about the use-livecode
mailing list