aio-libs / aiozmq

Asyncio (pep 3156) integration with ZeroMQ
aiozmq.readthedocs.org
BSD 2-Clause "Simplified" License
422 stars 56 forks source link

noob question: correct way to write message in route protocol #127

Open coinicon72 opened 7 years ago

coinicon72 commented 7 years ago

I'm new to python/pyzmq/aiozmq, so this maybe a very basic question for you guys, thanks.

I tried the very first example from doc, http://aiozmq.readthedocs.io/en/v0.8.0/examples.html#simple-dealer-router-pair-implemented-on-core-level , works just fine.

When I inspected the message msg received from the dealer (at ZmqRouterProtocol::msg_received) and found the value of message was <class 'list'>: [b'\x00\x80\x00\x00)', b'data', b'ask', b'0'], which has a extra element at position 0.

Then, I changed source code slightly, tried to send back message like this: # self.transport.write(msg) # comment out the original code self.transport.write([b'hello']) # change to this line But this does no working, the dealer can't get any response.

Turns out I need sent message like this: self.transport.write([msg[0], b'hello']) # add extra head to send message correctly this just no feel right

So, my question is:

  1. why there's a extra head (first element) in the message received in router
  2. what's the right way to send message in router

Thanks in advance.