# Problem with StreamingSocket::WaitForNextConnection

**URL:** <https://forum.juce.com/t/problem-with-streamingsocket-waitfornextconnection/2626>\
**Category:** Windows\
**Created:** [March 5, 2008, 8:27pm UTC](https://forum.juce.com/t/problem-with-streamingsocket-waitfornextconnection/2626 "2008-03-05T20:27:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raleks](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@raleks](https://forum.juce.com/u/raleks)\
**Post date:** [March 5, 2008, 8:27pm UTC](https://forum.juce.com/t/problem-with-streamingsocket-waitfornextconnection/2626/1 "2008-03-05T20:27:42Z")

</div>

Hi,

I have a challenge to get sockets to work, I gave up the DatagramSocket and now have tried out the StreamingSocket class. The code fails at the const int newSocket = (int) accept (handle, &address, &len); statement, so that code after this statement does not execute and my program does wierd things. Wonder what could cause this problem?

regards,  
Rune

```auto
StreamingSocket* StreamingSocket::waitForNextConnection() const
{
    jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
                                         // prepare this socket as a listener.

    if (connected && isListener)
    {
        struct sockaddr address;

#if defined (JUCE_LINUX) || (defined (JUCE_MAC) && ! MACOS_10_2_OR_EARLIER)
        socklen_t len = sizeof (sockaddr);
#else
        int len = sizeof (sockaddr);
#endif
        const int newSocket = (int) accept (handle, &address, &len);

        if (newSocket >= 0 && connected)
            return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
                                        portNumber, newSocket);
    }

    return 0;
}
```

---

<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:** [March 6, 2008, 1:46pm UTC](https://forum.juce.com/t/problem-with-streamingsocket-waitfornextconnection/2626/2 "2008-03-06T13:46:45Z")

</div>

It’s probably just failing to connect - you could add a call to WSAGetLastError to see what the exact error message was?

---

<div class="post-metadata">

**Author:** ![raleks](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@raleks](https://forum.juce.com/u/raleks)\
**Post date:** [March 11, 2008, 12:07pm UTC](https://forum.juce.com/t/problem-with-streamingsocket-waitfornextconnection/2626/3 "2008-03-11T12:07:29Z")

</div>

Found the problem, but don’t understand why it should fail. I had all the server socket code in a separate task. That made the accept call crash. Moving the code to my Juce component, the accept call works just fine. Strange.
