Sending raw bytes over ZeroMQ in Python

I am porting some Python code that uses raw TCP sockets for ZeroMQ for better stability and a cleaner interface.

From the very beginning, I see that one packet of raw bytes is not sent, as I expect.

In raw sockets:

import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) sock.send('\x00\x01\x02 and some more raw bytes') 

What is the current working code. This is the same code using ZeroMQ:

 import zmq context = zmq.Context() sock = context.socket(zmq.REQ) # this connection utilizes REQ/REP sock.connect('tcp://{0}:{1}'.format(HOST, PORT)) sock.send('\x00\x01\x02 and some more raw bytes') 

But when I check the packets going through the network, they are definitely not what I expect. What am I missing here?

In addition, when testing this code on the loopback interface ( 127.0.0.1 ) with a dummy server, it works fine.

Use Python 2.7 if that matters (unicode or whatnot).

+6
source share
1 answer

O. Wow. I overlooked the main drawback of my test, the remote server I was testing on was expecting a raw TCP connection, not a ZMQ connection.

Of course, ZMQ could not send the message, it did not even negotiate the connection successfully. When I tested locally, I tested the dummy ZMQ server, so it worked fine.

If I posted the server code, it would immediately mean that this is a problem.

In any case, sorry for the false alarm.

+4
source

Source: https://habr.com/ru/post/926401/


All Articles