0

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?

nutrx
  • 116
  • 4
  • 1
    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"). – larsks Jul 25 '21 at 12:53
  • Ah I see, that works, thank you! – nutrx Jul 26 '21 at 06:02

1 Answers1

1

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").

nutrx
  • 116
  • 4