nanomsg / nnpy

cffi-based Python bindings for nanomsg
MIT License
117 stars 39 forks source link

IPC PUB-SUB protocol doesn't work #48

Closed peetonn closed 6 years ago

peetonn commented 7 years ago

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

publisher:

>>> import nnpy
>>> pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
>>> pub.bind('ipc://qwer')
1
>>> pub.send('wazup')

subscriber:

>>> import nnpy
>>> sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
>>> sub.connect('ipc://qwer')
1
>>> sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')
>>> sub.recv()

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

djc commented 7 years ago

I don't think there is anything Python-specific here. I tried with the following script:

import nnpy

pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
print('bind', pub.bind('ipc://qwer'))

sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
print('connect', sub.connect('ipc://qwer'))
sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')

print('send', pub.send('wazup'))
print('recv', sub.recv())

This seems to hang on the receive with ipc, but runs to completion with inproc. So there's probably some nanomsg-internal problem. I recommend you write the equivalent C code and see if you can get that working -- if it doesn't, we can do more investigation, but it seems pretty unlikely to me the problem is in nnpy.

(IPC could also depend on your OS, which one are you testing here? If on a Unix, the IPC name probably has to be a filesystem path, so you could try something more along the lines of ipc:///tmp/qwer -- although that didn't resolve the problem for me on Linux.)

xgdgsc commented 6 years ago

https://github.com/nanomsg/nanomsg/issues/824 I encountered this and solved by not exiting too quickly.

djc commented 6 years ago

Good to hear! I'll close this.