Python [Errno 98] Address already in use

前端 未结 9 2667
一个人的身影
一个人的身影 2020-11-27 10:35

In my Python socket program, I sometimes need to interrupt it with Ctrl-C. When I do this, it does close the connection using socket.close().

9条回答
  •  孤独总比滥情好
    2020-11-27 10:44

    Yes, it is intended. Here you can read detailed explanation. It is possible to override this behavior by setting SO_REUSEADDR option on a socket. For example:

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

提交回复
热议问题