Fixed ofxOsc Broadcast to in OF 0.84 under Windows

I spent almost three hours finding this one, so I’d like to let you guys know…

Calling ofxOscSender.setup() with the local network broadcast-address ( under windows throws an exception (“std::runtime_error(“unable to connect udp socket\n”);”) in UdpSocket::Implementation::Connect() located in the file “UdbSocketWin.cpp”.

This is because the broadcast address is translated to in SockaddrFromIpEndpointName. Fixing SockaddrFromIpEndpointName is hard because that behavior is expected in other places. (Setting up a Receiver will fail if you do)

As a quick and dirty sollution, modify UdpSocket::Implementation::Connect() in File “UdbSocketWin.cpp” as follows to make things work:

    void Connect( const IpEndpointName& remoteEndpoint )
        SockaddrFromIpEndpointName( connectedAddr_, remoteEndpoint );
        // fix to allow local broadcasts
        //end fix

        if (connect(socket_, (struct sockaddr *)&connectedAddr_, sizeof(connectedAddr_)) < 0) {
            throw std::runtime_error("unable to connect udp socket\n");

        isConnected_ = true;

that broadcast address not always works, it’s better to use or the equivalent for you network + subnetwork mask. you can check it in windows calling ipconfig on a terminal i think