2

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?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

lets say i am using 54321 port. how can i stop it? sock.close('54321') ?
If your program does not own that application running at the port, you cannot stop it. And sock.close() will shutdown the program. No need of giving port. Looks like a little reading of "Socket Programming Howto" would be helpful to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.