Fixed ofxOsc Broadcast to 255.255.255.255 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 (255.255.255.255) 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 0.0.0.0 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
        if(remoteEndpoint.address==IpEndpointName::ANY_ADDRESS){
            connectedAddr_.sin_addr.s_addr=INADDR_BROADCAST;
        }
        //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 192.168.1.255 or the equivalent for you network + subnetwork mask. you can check it in windows calling ipconfig on a terminal i think