Python Socket Timeout setting

Source: Internet
Author: User

You need to set the method before calling the Connect method of the socket settimeout(time) , and then set the settimeout(None) socket into block mode again after the setting is called again.

The following code example:

Sock=Socket.Socket(Socket.af_inet, Socket.sock. (10) sock.< Span class= "PLN" >connect (addresssock< Span class= "pun". settimeout (none) = Sock. ( ' RB ' , 0              



Originally, the socket once set timeout, entered the non-blocking work mode, the original send () and recv () and so on is completely different, may only send or receive some data, need to check the return value and retry several times. Even makefile () is not allowed at all, it has been explicitly stated in the documentation of the socket module, but it is seldom noticed if it is not a somersault here.

With this in mind, it is much more complicated to write the correct code to work in the non-blocking mode, especially for text protocols that do not initially determine the length of the data.

Blocking and non-blocking are completely two different ways of using, not adding a socket.settimeout ().

Python Socket Timeout setting

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.