# Killing a StreamingSocket listener

**URL:** <https://forum.juce.com/t/killing-a-streamingsocket-listener/4216>\
**Category:** General JUCE discussion\
**Created:** [August 27, 2009, 4:05pm UTC](https://forum.juce.com/t/killing-a-streamingsocket-listener/4216 "2009-08-27T16:05:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![snortblt](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@snortblt](https://forum.juce.com/u/snortblt)\
**Post date:** [August 27, 2009, 4:05pm UTC](https://forum.juce.com/t/killing-a-streamingsocket-listener/4216/1 "2009-08-27T16:05:45Z")

</div>

Is there a recommended way to abort a StreamingSocket::waitForNextConnection call? It blocks indefinitely until a connection is made. Is there no way to poll for a connection so I can kill my listener thread gracefully?

---

<div class="post-metadata">

**Author:** ![X-Ryl669](https://avatars.discourse-cdn.com/v4/letter/x/a5b964/32.png) [@X-Ryl669](https://forum.juce.com/u/X-Ryl669)\
**Post date:** [August 28, 2009, 10:19am UTC](https://forum.juce.com/t/killing-a-streamingsocket-listener/4216/2 "2009-08-28T10:19:38Z")

</div>

You’ll need to put the socket in non blocking mode.  
Then call accept as usual, it’ll exit immediately with an error.  
Then select when the socket is writable, it means it’s connected.  
Select with a timeout, obviously.

---

<div class="post-metadata">

**Author:** ![snortblt](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@snortblt](https://forum.juce.com/u/snortblt)\
**Post date:** [November 16, 2009, 8:47pm UTC](https://forum.juce.com/t/killing-a-streamingsocket-listener/4216/3 "2009-11-16T20:47:52Z")

</div>

Hi. I’m just now getting back to this issue. X-Ryl thanks for the response, but it makes no sense. Can you please elaborate? Can anyone else weigh in on this. It seems like waitForNextConnection is virtually useless if the wait can’t be gracefully aborted.

---

<div class="post-metadata">

**Author:** ![X-Ryl669](https://avatars.discourse-cdn.com/v4/letter/x/a5b964/32.png) [@X-Ryl669](https://forum.juce.com/u/X-Ryl669)\
**Post date:** [November 17, 2009, 8:27am UTC](https://forum.juce.com/t/killing-a-streamingsocket-listener/4216/4 "2009-11-17T08:27:46Z")

</div>

Solution 1:  
before doing a “waitForInputConnection()”, do a

```auto
if (socket.waitUntilReady(true, 200))
    client = socket.waitForInputConnection()
```

I’m using this solution, it works perfectly.

Solution 2:  
Put the socket in non-blocking mode.  
(see setSocketBlockingState function).  
Then perform your own accept call, it will fail unless a connection is accepted.  
Use this if you have multiple socket to monitor at once.

---

<div class="post-metadata">

**Author:** ![snortblt](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@snortblt](https://forum.juce.com/u/snortblt)\
**Post date:** [November 17, 2009, 5:15pm UTC](https://forum.juce.com/t/killing-a-streamingsocket-listener/4216/5 "2009-11-17T17:15:25Z")

</div>

Ah. That’s much clearer. I think I’ll choose door #1. Thanks.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 9:50am UTC](https://forum.juce.com/t/killing-a-streamingsocket-listener/4216/6 "2017-05-12T09:50:17Z")

</div>


