tonysimpson / nanomsg-python

nanomsg wrapper for python with multiple backends (CPython and ctypes) should support 2/3 and Pypy
MIT License
382 stars 85 forks source link

IPC PUB-SUB protocol doesn't work #62

Open peetonn opened 6 years ago

peetonn commented 6 years ago

Trying to test with IPC protocol, but messages are never received:

publisher:

>>> from nanomsg import Socket, PUB, SUB
>>> s = Socket(PUB)
>>> s.bind('ipc://test')
<BindEndpoint socket <Socket fd 0, connected to [], bound to ['ipc://test']>, id 1, address 'ipc://test'>
>>> s.send(b'test\n')

subscriber:

>>> from nanomsg import Socket, PUB, SUB
>>> s = Socket(SUB)
>>> s.connect('ipc://test')
<ConnectEndpoint socket <Socket fd 0, connected to ['ipc://test'], bound to []>, id 1, address 'ipc://test'>
>>> s.recv()

Is there anything Python-specific for IPC I'm missing out here? I tried nnpy - it doesn't work either.

ollvai commented 6 years ago

Seems to be working just fine, you're just missing the subscribe definition:

>>> import nanomsg
>>> nanomsg.__version__
'1.0'
>>> from nanomsg import Socket, PUB, SUB
>>> p = Socket(PUB)
>>> p.bind(b"ipc://test")
<BindEndpoint socket <Socket fd 0, connected to [b'ipc://test'], bound to []>, id 1, addresss b'ipc://test'>
>>> p.send(b"test")
>>> from nanomsg import Socket, PUB, SUB, SUB_SUBSCRIBE
>>> s = Socket(SUB)
>>> s.connect(b"ipc://test")
<ConnectEndpoint socket <Socket fd 0, connected to [], bound to [b'ipc://test']>, id 1, addresss b'ipc://test'>
>>> s.set_string_option(SUB, SUB_SUBSCRIBE, b'')
>>> s.recv()
b'test'

Tested with Windows 7. Checkout nanomsg tests for more examples: https://github.com/tonysimpson/nanomsg-python/tree/master/tests