Shutting down sockets properly

前端 未结 3 1196
暖寄归人
暖寄归人 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: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 :).

提交回复
热议问题