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

**URL:** <https://discourse.julialang.org/t/using-zmq-as-a-simple-gateway-causes-linux-to-report-address-already-in-use/79538>\
**Category:** New to Julia\
**Tags:** zmq\
**Created:** [April 15, 2022, 4:08pm UTC](https://discourse.julialang.org/t/using-zmq-as-a-simple-gateway-causes-linux-to-report-address-already-in-use/79538 "2022-04-15T16:08:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [April 15, 2022, 4:08pm UTC](https://discourse.julialang.org/t/using-zmq-as-a-simple-gateway-causes-linux-to-report-address-already-in-use/79538/1 "2022-04-15T16:08:47Z")

</div>

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

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

```

the relevant code is:

source

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

```

gateway

```julia
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

```julia
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
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

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

```

Why is this happening please?  
thank you.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 15, 2022, 4:15pm UTC](https://discourse.julialang.org/t/using-zmq-as-a-simple-gateway-causes-linux-to-report-address-already-in-use/79538/2 "2022-04-15T16:15:25Z")

</div>

> [@anon69491625](#):
>
> ```julia
> ZMQ.bind(in_socket, "tcp://*:5555")
> ZMQ.bind( out_1_socket, "tcp://*:5559")
> 
> ```

> [@anon69491625](#):
>
> `ZMQ.bind(in_socket, "tcp://*:5559")`

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.

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [April 15, 2022, 7:39pm UTC](https://discourse.julialang.org/t/using-zmq-as-a-simple-gateway-causes-linux-to-report-address-already-in-use/79538/3 "2022-04-15T19:39:46Z")

</div>

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