wrote:
> hi everyone,
>
> This ones makes me scratch my head : I'm using the following script on
> Windows and it looks like I can run two instances of it
> simultaneously...which means that I have 2 servers listening on the
> same port.
>
> #!/usr/bin/perl -w
> use strict;
> use Socket;
> my $port = 8080;
> my $proto = getprotobyname('tcp');
> socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
> setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die
> "setsockopt: $!";
Get rid of the SO_REUSEADDR. IIRC this will have the disadvantage that you
may have to wait a bit before you can reopen the socket after a close.
> bind(Server, sockaddr_in($port, INADDR_ANY)) || die "bind: $!";
> listen(Server,SOMAXCONN) || die "listen: $!";
> print "Server : server started on port $port\n";
> while(1) {}
>
> I was expecting an error like "port already in use". Am I doing
> something wrong ?
>
You might find IO::Socket easier to use.
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e. r^.>l^..>k^.-