In general, the timeout setting in Io::socket::inet is for Conncet
If you want to set the RECV receive timeout, you can set this:
1UsrSocket:2......3 setsockopt($socket, Sol_socket, So_rcvtimeo,Pack('l!l!',1,0));4 #Note that there are three parameters in the pack, and the following 1 indicates a timeout of 1 seconds, and the last 0 you can default5 #而前面的 ' l!l! ',! Represents a 64-bit platform6 #如果你是用IO:: Socket::inet His Socket, can be like this:7 UseIo::Socket::INET;8 my $socket= IO::Socket::inet->new ();9 $socket-setsockopt(Sol_socket, So_rcvtimeo,Pack('l!l!',1,0));Ten One #If you feel trouble, you can install the Io::socket::timeout module and set the receive timeout or send timeout as follows: A # 1. Creates a socket as usual - my $socket= IO::Socket:: Inet->new (... ); - the #2. Enable Read and write timeouts on the socket -Io::Socket:: timeout->enable_timeouts_on ($socket); - - #3. Setup the Timeouts + $socket->read_timeout (0.5); - $socket->write_timeout (0.5); + A #4. Use the socket as usual at my $data= <$socket>; - - #
Here's one thing to note, maybe the new guy is a little confused.
That is when io::socket::inet creates a socket, the socket is undefined, and it becomes a defined state until it is connected successfully.
So, when you use Io::socket::timeout, remember to connect to the success of the call, without error, the hint method cannot be used for an undefined variable.
As shown in the code above, if you put 20 rows in the 17 row position, the program will go wrong.
Article reference from: http://blog.booking.com/socket-timeout-made-easy.html
Perl Socket Receive Timeout setting