Perl Socket Receive Timeout setting

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.