Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Making IO::Socket::UNIX client time out

by kroach (Pilgrim)
on Oct 02, 2019 at 13:25 UTC ( #11106959=note: print w/replies, xml ) Need Help??


in reply to Re: Making IO::Socket::UNIX client time out
in thread Making IO::Socket::UNIX client time out

IO::Socket does handle Timeout, what's more, it actually works in the server part of IO::Socket::UNIX. This server will stop if it doesn't receive a connection within 2 seconds:
#!/usr/bin/perl use strict; use warnings; use IO::Socket::UNIX; use constant SOCKET => 'test_socket.sock'; my $mode = shift or die "Specify a mode\n"; if ($mode eq 'server') { my $server = IO::Socket::UNIX->new( Type => SOCK_STREAM, Local => SOCKET, Listen => 1, Timeout => 2, ) or die $!; while (my $conn = $server->accept()) { my $name = <$conn>; print {$conn} "Hello $name"; close $conn; } print 'Timed out', "\n"; } elsif ($mode eq 'client') { my $client = IO::Socket::UNIX->new( Type => SOCK_STREAM, Peer => SOCKET, ) or die $!; print {$client} 'John', "\n"; print "Got reponse: ", scalar <$client>; close $client; } else { die "Unsupported mode: $mode\n"; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2020-10-20 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (209 votes). Check out past polls.

    Notices?