0

I am trying to send a message to switch through socket in python. Switch and host are created through mininet with the command like below.

sudo mn --switch ovsk --topo tree,depth=2,fanout=8 --controller=remote,ip=127.0.0.1,port=6633

In the client side, I used socket like below.

import socket
host = socket.gethostbyname("")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, 6633))

message = np.random.choice(normalized_x[0], 1, replace=False)

s.send(message.encode())
s.close()

On the server side, code is like below.

host = socket.gethostbyname("")
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
      s.bind((host, 6633))          # Define ip address as local host and port number
      s.listen(1)                       # Listen for incoming connection
      clt, addr = s.accept()


      c_messg = clt.recv(10240)                # Store message received from the server

      temp_msg = c_messg.decode()
      s.close()

However, whenever I execute those python files, I get an error message that is

error: [Errno 98] Address already in use

I am not sure about how to resolve this problem. Thank you for your answer in advance.

dkssud
  • 3
  • 4
  • Are the client and server both running on the same machine? If they are, you need to use SO_REUSEADDR – cup May 09 '20 at 10:56
  • Does this answer your question? [Python \[Errno 98\] Address already in use](https://stackoverflow.com/questions/4465959/python-errno-98-address-already-in-use) – Prayson W. Daniel May 09 '20 at 10:56
  • I have already tried SO_REUSEADDR. It does not fix the error... – dkssud May 10 '20 at 04:18

1 Answers1

0

The error means that the Address that your server is trying to listen on is already in use by another process. you can use

sudo lsof -i :6633

to see which process is listening on the same port

or if its doable, you can switch to a different port that is not in use.

if nothing shows up with netstat or lsof

You may want to look at Link and Link too

Shehroze Malik
  • 111
  • 1
  • 10
  • In my case, sudo lsof -i :6633 does not give me any process is running. But when I run the file and launch socket, sudo lsof -i :6633 starts to have processes which is not possible to kill because I have to run it with socket. – dkssud May 10 '20 at 04:19