Problem with StreamingSocket::WaitForNextConnection



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?


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);
        int len = sizeof (sockaddr);
        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;


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


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.