keijiro / OscJack

Lightweight C# implementation of OSC server/client
The Unlicense
465 stars 64 forks source link

OscClient broadcast fails on IOS. #39

Open zacksettel opened 1 year ago

zacksettel commented 1 year ago

OscClient enables broadcast only for one address: "255.255.255.255", and this address fails on my IOS device. Broadcast is enabled but the network but broadcasting is not permitted.

If OscClient enabled broadcast for any address of the form "xxx.xxx.xxx.255" then broadcast over the a local network (eg. "192.168.0.255" ) will likely be permitted, which is the case on nearly the local networks I have used. Since I use local broadcast quite often, not having that option for my IOS builds is a bummer.

Proposed solution:

I modified and tested the following code, which worked on my desktop and IOS builds.

    public OscClient(string destination, int port)
    {
        _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

        if ( String.Equals(destination.Substring(destination.Length-3),  "255"))
        //if (destination == "192.168.0.255")
            _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);

        var dest = new IPEndPoint(IPAddress.Parse(destination), port);
        _socket.Connect(dest);
    }

Hopefully this makes sense and is a resonable request.