ZMQ - correct usage

trying to get a simple ZMQ communication going connecting to a simple python echo server

import zmq

# ZeroMQ Context
context = zmq.Context()

# Define the socket using the "Context"
sock = context.socket(zmq.REP)
sock.bind("tcp://127.0.0.1:1234")

# Run a simple "Echo" server
while True:
    message = sock.recv()
    sock.send("Echo: " + message)
    print "Echo: " + message

Julia code for the client looks like

using ZMQ
const ctx = Context()
const sock = Socket(ctx, REQ)
ZMQ.connect(sock, "tcp://127.0.0.1:1234")
ZMQ.send(sock, "SUCCESS")

that works for the first connection - but there doesn’t appear to be persistance if I send
ZMQ.send(sock, “SUCCESS”)

I have to reestablish context like

ctx = Context()
s = Socket(ctx, REQ)
ZMQ.connect(s, "tcp://localhost:1234")

and not

ZMQ.send(sock, "SUCCESS")

that cant be right is it
tks

You need to call recv(sock) from Julia after every time you call send, otherwise you won’t be able to send any more messages. This is just part of the required behavior of a REQ-REP connection.

2 Likes