Python Network Stall

Viewed 34

trying to ping a server from a client like this:

#server
import socket

HOST = ''
PORT = 50007 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)

conn, addr = s.accept()
print ('Connected by', addr)
while 1:
  data = conn.recv(1024)
  if not data: break
  conn.sendall(data)
conn.close()
#client
import socket

HOST = ''
PORT = 50007 

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall(b"Hello, world")
    data = s.recv(1024)

print(f"Received {data!r}")

But there is a hang on server side after the s.accept(), and ...[111] connection refused on the client side.

BTW: I am on a windows machine for the server, and pinging from a linux machine. They are connected with an ethernet cable. I have also set a static address for the linux machine, from the windows machine.

Another thing, is that the exact same code works in the opposite direction ...

Could someone help?! Stuck on this for ages!

0 Answers
Related