Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: TCP Server timeout

by leighsharpe (Monk)
on Feb 23, 2010 at 03:59 UTC ( #824756=note: print w/replies, xml ) Need Help??


in reply to TCP Server timeout

The 'timeout' option to IO::Socket will do what you want:
#!/usr/bin/perl use strict; use warnings; use IO::Socket; my $server=IO::Socket->new( Domain=>AF_INET, Proto=>'tcp', LocalPort=>'1234', Listen=>SOMAXCONN, ); $server->timeout(10); my $connection=$server->accept; if ($connection) { print "Got a message.\n"; close $connection; } else { print "Timed out.\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://824756]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2022-09-27 04:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (118 votes). Check out past polls.

    Notices?