Shutting down sockets properly

前端 未结 3 1195
暖寄归人
暖寄归人 2021-01-15 02:00

I\'m trying to make a server / client connection with sockets. But they will not close properly and I can\'t wrap my head around why.

Update 1

I\'ve corre

相关标签:
3条回答
  • 2021-01-15 02:10

    you are calling s.close, instead of s.close().

    you need to invoke the socket.close() method if you want the client to terminate the connection.`

    0 讨论(0)
  • 2021-01-15 02:18
    s.close                     # Close the socket when done
    

    Sticks out to my eyes because you don't actually CALL anything, you should try s.close()

    0 讨论(0)
  • 2021-01-15 02:28

    you need socket.socket.setsockopt, .i.e s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    Though the socket will be closed by the os when process ended, it is a good behavior to call close() explicitly. However, after that, the local addr(local_ip, local_port) is not avaiable until 2 MSL(maximum segment lifetime) has passed. Why? and what we can do? you can read these:

    http://www.tcpipguide.com/free/t_TCPConnectionTermination-3.htm and http://www.unixguide.net/network/socketfaq/4.5.shtml

    It will be difficult to me to post it more clear than they do :).

    0 讨论(0)
提交回复
热议问题