1

I try to implement a REQ/REP pattern, with python3 asyncio and ZeroMQ

My client async function:

import zmq
import os
from time import time
import asyncio

import zmq.asyncio


print ('Client %i'%os.getpid())

context = zmq.asyncio.Context(1)
loop = zmq.asyncio.ZMQEventLoop()
asyncio.set_event_loop(loop)


async def client():
    socket = context.socket(zmq.REQ)
    socket.connect('tcp://11.111.11.245:5555')
    while True:
        data = zmq.Message(str(os.getpid()).encode('utf8'))
        start = time()
        print('send')
        await socket.send(data)
        print('wait...')
        data = await socket.recv()
        print('recv')
        print(time() - start, data)


loop.run_until_complete(client())

As I understand, the call to a socket.connect( "tcp://11.111.11.245:5555" ) method is a blocking method.

How to make a non-blocking connection call, in my case?

1 Answer 1

1

As far as I understand the ZeroMQ API, the call to .connect() method is not synchronous with building the real connection ( if not introduced by the wrapper, the underlying API is non-blocking - ref. below ).

The connection will not be performed immediately but as needed by ØMQ. Thus a successful invocation of zmq_connect() does not indicate that a physical connection was or can actually be established.

Ref.: ZeroMQ API - zmq_connect(3)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.