Using ZMQ as a simple gateway causes linux to report "Address already in use"

Hi there

I want to send a message from one julia script (SOURCE ) to another (GATEWAY) and that one send the message onto another script ( DESTINATION).

So the ZMQ flow is

source PUSH to 5555 
gateway PULL 5555 PUSH 5559
destination PULL 5559

the relevant code is:

source

context = Context()
stk_socket = Socket(context, PUSH)
ZMQ.connect(stk_socket, "tcp://localhost:5555")
ZMQ.send(stk_socket, send_msg)             #"Hello" )

gateway

using ZMQ
context = Context()
in_socket = Socket(context, PULL)
out_1_socket = Socket(context, PUSH)
ZMQ.bind(in_socket, "tcp://*:5555")
ZMQ.bind( out_1_socket, "tcp://*:5559")
message = String(ZMQ.recv(in_socket))
send_msg = "LAST~AAPL~1243.23~" * string(message)
ZMQ.send(out_1_socket, send_msg)        

destination

using ZMQ
context = Context()
in_socket = Socket(context, PULL)
ZMQ.bind(in_socket, "tcp://*:5559")
message = String(ZMQ.recv(in_socket))
println("Received request: $message")

I start GATEWAY first in a terminal window

julia      352957            dave   30u  IPv4 87864640      0t0  TCP *:5555 (LISTEN)
julia      352957            dave   31u  IPv4 87864641      0t0  TCP *:5559 (LISTEN)

I open another terminal window and start DESTINATION I get

ERROR: LoadError: StateError("Address already in use")

Why is this happening please?
thank you.

If you’re running all of these on the same machine, all of these calls try to bind their socket to the same port. That’s why you’re getting the error that the address is already in use.

1 Like

thanks for the heads up. I AM running these on the same machine.