samy
samy

Reputation: 21

python socket programming error

i got this error while running my function.

"socket.error: [Errno 98] Address already in use"

how can i close the address already in use and start new connection with port in python?

Upvotes: 2

Views: 2857

Answers (2)

Zealot Ke
Zealot Ke

Reputation: 503

These scenarios will raise error "[Errno 98] Address already in use" when you create a socket at certain port:

  1. The port was't closed. When you created a socket, but forgot to close it, or annother program hold that.

  2. You have close the socket(or kill the process), but the port stay at TIME_WAIT status in 2 MSL(about 2 minutes).

Try "netstat" command to view port usage

such as

netstat -na

or

netstat -na |grep 54321

Upvotes: 3

Senthil Kumaran
Senthil Kumaran

Reputation: 56951

Stop the program or the service which is the port which you are trying to use. Alternatively, for whatever program which you are trying to write, use a PORT number which is a sufficiently high number (> 1024 for sure) and is unused.

Upvotes: 0

Related Questions