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

connection timeout #72

Open hamzehnasajpour opened 5 years ago

hamzehnasajpour commented 5 years ago

After creating a socket, how can I find out that the connection path is available or not? Please see the following codes, assume that path isn't available. How can I detect it after s1.connect(path)?

s1 = Socket(PUSH)
s1.connect(path)
s1.send(makeCapnpPacket().to_bytes())
tonysimpson commented 5 years ago

connect returns an endpoint object that has an address attribute

e1 = s1.connect(path) e1.address all endpoints are also available as a list on the socket

s1.endpoints

hamzehnasajpour commented 5 years ago

My m My main problem is that ipc_path = "ipc://test" isn't available, and no body listen to it, how can I detect that ipc_path is available and I could connect it successfully.

ipc_path = "ipc://test"
s1 = Socket(PUSH)
s1.connect(ipc_path)
tonysimpson commented 5 years ago

Ok I see a problem. Testing between process on ubuntu 18.10 with libnanomsg version 0.8~beta+dfsg-1 (that's very old?) I can't connect between the two using 'ipc://test' - lsof shows two separate unix sockets called test. using 'ipc:///tmp/test' work fine.

Is this the same issue you are having?

hamzehnasajpour commented 5 years ago

Sorry, This is an misunderstanding. One process(server) listen to a Unix Socket, and another process(client) can connect to it by this socket. If the server does not exist so there is no Unix Socket (ipc_path) so when my client connect to it, how can I detect that this path is available or not? How can I detect that I can send data to it or the server not available?

tonysimpson commented 5 years ago

Ah Ok. Depends on your use case I guess. But if you just want to exit the client if the server is not there you could set a socket timeout with recv_timeout? But I've just tried it and it seems broken. What are your OS, Python version and architecture (x86_64?)?

hamzehnasajpour commented 5 years ago

Sorry for late reply. I'm using Ubuntu 18.04 (x86_64) with Python2.7.

How can I change the socket timeout for recv or send?