Simple pair communication with pynng

180 views Asked by At

I am trying to set up a very simple pair communication using pynng, but the listening instance never seems to receive any messages when sending via TCP from a different device.

client.py

s = Pair0(send_timeout=10000)
s.dial('tcp://192.168.0.44:5556')
time.sleep(2)

try:
    s.send(b'asdf')
except pynng.exceptions.Timeout:
    pass

s.close()

server.py

s = Pair0(recv_timeout=10000)
s.listen('tcp://127.0.0.1:5556')
time.sleep(2)

try:
    print(s.recv())
except pynng.exceptions.Timeout:
    pass

s.close()

so really I am just trying to send anything to the server here, but it never receives anything. What am I missing here?

1

There are 1 answers

0
nutrx On

As @larsks pointed out in the comments

You are binding your server to the loopback address, 127.0.0.1. This address is only available on the local machine. If you expect your server to accept connections from other devices on the network, you need to bind to a nonlocal ip address, or 0.0.0.0 (which means "all addresses").