# Flushing ZMQ pipe before use?

**URL:** <https://discourse.julialang.org/t/flushing-zmq-pipe-before-use/86893>\
**Category:** New to Julia\
**Tags:** zmq\
**Created:** [September 7, 2022, 1:57pm UTC](https://discourse.julialang.org/t/flushing-zmq-pipe-before-use/86893 "2022-09-07T13:57:57Z")\
**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:** [September 7, 2022, 1:57pm UTC](https://discourse.julialang.org/t/flushing-zmq-pipe-before-use/86893/1 "2022-09-07T13:57:57Z")

</div>

Hi all  
this is very strange. I am using ZMQ and after I have finished with it I shut it down using close BUT when I start it up again there’s “END” in there???

```julia
using ZMQ
context = Context()
socket = Socket(context, PULL)
ZMQ.bind(socket, "tcp://*:5555")

while true 
do some stuff looking at messages

if message == "END"
      println("dying")
      println(df_table)
      ZMQ.close(socket)
      ZMQ.close(context)
      break
   end

```

I “kill” it using this which I “thought” would flush the buffer/socket when I close the PULL

```julia
using ZMQ
context = Context()
stk_socket = Socket(context, PUSH)
ZMQ.connect(stk_socket, "tcp://localhost:5555")
ZMQ.send(stk_socket,"END")
ZMQ.close(stk_socket)
ZMQ.close(context)

```

Is there a FLUSH function in ZMQ that I can call in the PULL? to flush anything out of the socket?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 7, 2022, 2:05pm UTC](https://discourse.julialang.org/t/flushing-zmq-pipe-before-use/86893/2 "2022-09-07T14:05:25Z")

</div>

> [@anon69491625](#):
>
> Is there a FLUSH function in ZMQ that I can call in the PULL? to flush anything out of the socket?

From the [ZMQ FAQ](http://wiki.zeromq.org/area:faq):

> **How can I flush all messages that are in the ZeroMQ socket queue?** There is no explicit command for flushing a specific message or all messages from the message queue. You may set `ZMQ_LINGER` to `0` and close the socket to discard any unsent messages.

---

<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:** [September 7, 2022, 2:22pm UTC](https://discourse.julialang.org/t/flushing-zmq-pipe-before-use/86893/3 "2022-09-07T14:22:29Z")

</div>

hmm seems I should have done **SOME** research in the “HIDDEN” area called ZMQ FAQ. They could have gone the extra mile and called it “THIS IS FOR THE LAZY AND INDOLENT” 😉  
sorry about that @stevengj BUT it does say that I should close everything down, which I do on terminating the script. ALSO I check the status of the ports

```julia
sudo lsof -i -P -n | grep LISTEN

```

and it’s all gone bye bye as 5555 has no listeners. Ho hum back into the dog house for me and it’s only 9:30am

thanks again.  
theakson
