Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Checking whether a socket has been closed by the peer

Thread Tools

Checking whether a socket has been closed by the peer

Jakob Lell
Posts: n/a
how can I check whether the client has closed an IO::Socket::INET?
According to the description, the connected-Method of IO::Socket should
return undef if the socket isn't connected. However, this doesn't work
when the peer has closed the connection. When you run the script below
and connect to port 1234 from another terminal using netcat or telnet and
then close the connection, the script will continue to write "connected\n"
to STDOUT every second.

use IO::Socket;
my $sock=IO::Socket::INET->new(LocalPort=>1234,Listen=>5,ReuseAddr=>1)||di e $!;
while(my $client=$sock->accept()){
next unless defined($client);
while(defined $client->connected){
print "connected\n";

Is there any way to check whether the connection has been closed by the
peer? I've already tried eof and the has_exception method from
IO::Select, but neither solved my problem. I know I could try to read
anything from the socket but as I'm using nonblocking IO, this is no
solution for the problem.

I'm using Linux 2.6.5 and Perl 5.8.3.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
The printing has been stopped and this job has been add to the queu? dejola Computer Support 6 12-30-2005 03:26 AM
peer to peer linking and sharing =?Utf-8?B?QmlsbEM=?= Wireless Networking 2 08-23-2004 08:23 PM
Need help with peer to peer no hub network Doug A Moller Wireless Networking 3 06-24-2004 01:48 AM
Determining of a Socket has been closed by the other side. Dave Rudolf Java 3 12-31-2003 05:27 AM
Re: asking help for a peer-to-peer socket programming question Matt Gessner C Programming 1 07-17-2003 04:21 AM