Python socket connection timeout

后端 未结 3 1955
忘了有多久
忘了有多久 2020-11-30 00:45

I have a socket that I want to timeout when connecting so that I can cancel the whole operation if it can\'t connect yet it also want to use the makefile for the socket whic

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 01:36

    For setting the Socket timeout, you need to follow these steps:

    import socket
    socks = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    socks.settimeout(10.0) # settimeout is the attr of socks.
    

提交回复
热议问题