[Mono-list] Porting UPnP Tools to MONO - Socket "ExclusiveAddressUse" problem

Ylian ysainthilaire at hotmail.com
Mon May 10 18:05:50 EDT 2010


Hi.


I own the  http://opentools.homeip.net/dev-tools-for-upnp Developer Tools
for UPnP Technologies , I widely used set of tools for building and
debugging UPnP related software. I have gotten many requests to run the
tools on MONO and have gotten rid of all the C/C++ native code and so far,
it's working except for one problem:


I need to bind to UDP port 1900 non-exclusively to receive SSDP multicast
traffic. I use Ubuntu 10.04, MONO 2.4.4 and I get a "SocketException:
Protocol Option not supported" when trying to set UdpClient's
ExclusiveAddressUse property. Are there any alternatives?


I am also trying to find precedents for UPnP work on MONO. My multicast
socket setup code below (Apache 2.0 license).


Thanks,

Ylian

http://opentools.homeip.net/ opentools.homeip.net 



    public class UPnPMulticastSniffer

    {

        public delegate void PacketHandler(object sender, string Packet,
IPEndPoint Local, IPEndPoint From);

        public event PacketHandler OnPacket;

        private UdpClient client = null;


        public UPnPMulticastSniffer(IPEndPoint local)

        {

            client = new UdpClient(local.AddressFamily);


            client.ExclusiveAddressUse = false;

            client.Client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ExclusiveAddressUse, false);

            client.Client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReuseAddress, true);

            client.EnableBroadcast = true;

            client.Client.Bind(local);

            if (local.AddressFamily == AddressFamily.InterNetwork) 
client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"),
local.Address);
            if (local.AddressFamily == AddressFamily.InterNetworkV6) 
client.JoinMulticastGroup((int)local.Address.ScopeId,
IPAddress.Parse("FF02::C"));
            client.BeginReceive(new AsyncCallback(OnReceiveSink), null);

        }


        public void OnReceiveSink(IAsyncResult ar)

        {

            IPEndPoint ep = null;

            byte[] buf = null;

            try { buf = client.EndReceive(ar, ref ep); } catch (Exception) {
}

            if (buf != null && OnPacket != null) OnPacket(this,
UTF8Encoding.UTF8.GetString(buf, 0, 
buf.Length), (IPEndPoint)client.Client.LocalEndPoint, ep);
            try { client.BeginReceive(new AsyncCallback(OnReceiveSink),
null); } catch (Exception) { }

        }


        public void Dispose()

        {

            if (client == null) return;

            client.Close();

            client = null;

        }

    }



-- 
View this message in context: http://mono.1490590.n4.nabble.com/Porting-UPnP-Tools-to-MONO-Socket-ExclusiveAddressUse-problem-tp2173013p2173013.html
Sent from the Mono - General mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20100510/f8dd508c/attachment-0001.html 


More information about the Mono-list mailing list