Python server “Only one usage of each socket address is normally permitted”

后端 未结 7 1075
野趣味
野趣味 2020-11-30 06:21

I\'m trying to create a very basic server in python that listens in on a port, creates a TCP connection when a client tries to connect, receives data, sends something back,

7条回答
  •  被撕碎了的回忆
    2020-11-30 07:06

    In the article posted by @JohnKugelman it is stated that even after enabling SO_REUSEADDR you cannot use the socket to connect to the same remote end as before:

    SO_REUSADDR permits you to use a port that is stuck in TIME_WAIT, but you still can not use that port to establish a connection to the last place it connected to.

    I see that you are just testing/playing around. However, to avoid this error you really need to make sure that you terminate the connection properly. You could also mess with the tcp timings of the operating system: http://www.linuxquestions.org/questions/linux-networking-3/decrease-time_wait-558399/

    For testing purposes it would also be fine if you just change your serverPort in a round-robin fashion, what do you think?

提交回复
热议问题