wrote:
> Writing a small server where I want the server to stop accepting new
> connections after the inital client connects. I'm creating the socket
> as such:
> $sock = new IO::Socket::INET(
> LocalHost => $cip,
> LocalPort => $cport,
> Proto => 'tcp',
> Listen => 0,
> ReuseAddr => 1,
> );
> ($csock, $c_addr) = $sock->accept();
> ($c_port, $c_ip) = sockaddr_in($c_addr);
> $c_ipnum = inet_ntoa($c_ip);
> print "Client connecting from: $c_ipnum:$c_port\n";
>
> Once $csock gets defined (client connection), I would like the server
> to stop listening for new connections. If I use close on the original
> $sock
Your code does not show you using close on the original $sock.
> it closes $csock as well so I'm not quite sure how to go about
> achieving this.
I cannot verify this. I close $sock, and $csock goes merrily on its way,
just as I expected it to do.
Can you provide a complete, runnable program which reproduces your problem?
use IO::Socket::INET;
$sock = new IO::Socket::INET( LocalPort => 9999, Listen=> 0, ReuseAddr=> 1,
); ($csock, $c_addr) = $sock->accept();
($c_port, $c_ip) = sockaddr_in($c_addr);
$c_ipnum = inet_ntoa($c_ip);
print "Client connecting from: $csock $c_ipnum:$c_port\n";
close $sock or die $!;
print while <$csock>;
The first "telnet localhost 9999" I run connects, and stays connected for
as long as it wants, sending data to the server, which the server echos.
Any subsequent "telnet localhost 9999" I try to run gets a connection
refused.
Xho
--
--------------------
http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB