6

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

Right off the bat I can see that a single packet of raw bytes is not sent as I'm expecting.

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')

Which 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 inspect the packets going over the net, they're definitely not what I'm expecting. What am I missing here?

Also, when testing this code on the loopback interface (127.0.0.1) with a dummy server it seems to work just fine.

Using Python 2.7 if it matters (unicode or whatnot).

3
  • There is no output, I'm inspecting the raw network traffic, is that what you're looking for? Commented Sep 27, 2012 at 13:10
  • 1
    zeromq uses it's own data marshaling on sockets; if you sniff the packets, they don't have to be exactly the same Commented Sep 27, 2012 at 13:49
  • @BartekBanachewicz - very true, thanks. Notice my answer from just now. Commented Sep 27, 2012 at 13:50

1 Answer 1

4

Oh. Wow. I overlooked a major flaw in my test, the remote server I was testing on was expecting a raw TCP connection, not a ZMQ connection.

Of course ZMQ wasn't able to transfer the message, it didn't even negotiate the connection successfully. When I tested locally I was testing with a dummy ZMQ server, so it worked fine.

If I'd have posted the server code it would have immediately made sense that that was the problem.

In any case, sorry for the false alarm.

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.