[SOLVED] Python 2.7: socket.settimeout and shutdown not working?

8 thoughts on “[SOLVED] Python 2.7: socket.settimeout and shutdown not working?

  1. We are experiencing some very funky behavior when we try to either use a timeout via sock.settimeout(). The first time we use the socket it works find, but trying to create a new one and using it fails with a socket.error exception: 

    [Errno 11] Unknown error   <- What’s errno 11 on Telit? I’ve seen EAGAIN, EWOULDBLOCK and EDEADLK 

    Not setting the timeout works perfectly and I can create as many sockets as I want as long as I close the previous one (ctx 1).

     

     

    Trying to do shutdown(socket.SHUT_RD) on a socket before closing it causes an exception which I haven’t managed to figure out yet (not sure what the type is):

    Unhandled exception of type error. Arguments:

    (115, ‘Unknown error’)

     

     

    Are these known issues or are we doing something wrong? This is on UL865 devices running 12.00.603-B063.

  2. I’ve done some digging and here is a snippet which shows the behavior:

     

     

    import _socket as socket

    af, socktype, proto, canonname, sa = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0]

    sock = socket.socket(af, socktype, proto)

    sock.setsockopt(socket.SOL_SOCKET, socket.SO_CONTEXTID, 1)

    sock.settimeout(5.0)

    sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

    sock.connect((host, port))

    sock.sendall(‘GET / HTTP/1.1rn’)

    sock.sendall(‘rnrn’)

    print sock.recv(1024) 

     

     

     Running this on my computer (excluding the SO_CONTEXTID assignment) works. Running it on the modem will raise a socket.error on connect. If I don’t set the timeout the example works on the modem as well.

  3. please post the complete file running on PC

    This example works on the PC:

     

     

    import _socket as socket

     

    host = "google.com"

    port = 80

     

    af, socktype, proto, canonname, sa = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0]

    sock = socket.socket(af, socktype, proto)

    try:

       sock.setsockopt(socket.SOL_SOCKET, socket.SO_CONTEXTID, 1)

    except AttributeError:

       pass

    sock.settimeout(5.0)

    sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

    sock.connect((host, port))

    sock.sendall(‘GET / HTTP/1.1rn’)

    sock.sendall(‘rnrn’)

    print sock.recv(1024)