1

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

Thai Laoquoc
  • 95
  • 1
  • 2
  • 10

5 Answers5

6

I think you are trying to run more than one Odoo server on the same port.

Try this on terminal:

 sudo netstat -nlp | grep 8069

then you will see something like this:

 tcp        0      0 0.0.0.0:8069            0.0.0.0:*               LISTEN      10869/python2    

Kill the process:

sudo kill -9 10869

OR

Change the port number in the fileServer.py.

Then try to start Odoo.

Hope it will help you.

KbiR
  • 3,541
  • 2
  • 26
  • 73
1

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?

Jameel
  • 53
  • 5
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
Jithin M
  • 11
  • 2
0

you could use this command to kill the Odoo process already running on that port

fuser -k tcp/8069

and launch your python script again

Nwawel A Iroume
  • 755
  • 13
  • 30
-1

use this command is the correct sudo systemctl stop odoo11

if you use other version of odoo change the number 11 for your version