python-3.6odoo-11

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

  • 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.