'socket.error: [Errno 98] Address already in use
I have this code to connect with server, and this is fileServer.py on server, i have another file py at client but not test yet, i got problem when run this code, please see the information below
import socket
import threading
import os
def RetrFile(name, sock):
filename = sock.recv(1024).decode()
if os.path.isfile(filename):
message = "EXISTS" + str(os.path.getsize(filename))
sock.send(message.encode())
userResponse = sock.recv(1024).decode()
if userResponse[:2] == "OK":
with open(filename, 'rb') as f:
bytesToSend = f.read(1024)
sock.send(bytesToSend)
while (bytesToSend !=""):
bytesToSend = f.read(1024)
sock.send(bytesToSend)
else:
sock.send("ERR")
sock.close()
def Main():
host = '192.168.0.91'
port = 8069
s = socket.socket()
s.bind((host,port))
s.listen(5)
print('Server Started')
while True:
c, addr = s.accept()
print ('Client connected ip: ' + str(addr))
t = threading.Thread(target = RetrFile, args=('retrThread',c))
t.start()
s.close()
if __name__ == '__main__':
Main()
And when I run it, it show me an Error, I think it is about socket to connect with IP server, is it right?
File "fileServer.py", line 40, in <module>
Main()
File "fileServer.py", line 26, in Main
s.bind((host,port))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
How can I fix that? Any suggest? Thanks in advance
Solution 1:[1]
You can simply use the following script to kill the process.
fuser -k 8069/tcp
Generally,
fuser -k <port_no>/<tcp/udp>
OR
netstat -nlp | grep <port_no>
kill -9 PID
Solution 2:[2]
The error is self explanatory "Address already in use" return getattr(self._sock,name)(*args) socket.error: [Errno 98] Address already in use
@KbiR has already explained it
For windows check this out How can you find out which process is listening on a port on Windows?
Solution 3:[3]
you could use this command to kill the Odoo process already running on that port
fuser -k 8069/tcp
and launch your python script again
Solution 4:[4]
use this command is the correct sudo systemctl stop odoo11
if you use other version of odoo change the number 11 for your version
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jithin M |
| Solution 2 | Jameel |
| Solution 3 | |
| Solution 4 |
