nanowebcoder / NanoVeraHuesBridge

A C# version of a Philips Hues Bridge which allows Amazon Echo to speak to Vera and control lights, doors, stereos and more.
Apache License 2.0
14 stars 4 forks source link

Port conflicts (patch attached) #12

Closed gibman closed 6 years ago

gibman commented 6 years ago

A small change for "class SSDPService"

It allows for sharing the port with other processes as I kept getting exceptions when trying to start the service.

This means I do not have to close the SSDP discovery windows Service plus a lot of other apps that make use of port 1900

`public bool Start() { try { logger.Info("Starting SSDP Service on IP [{0}], port [{1}]...", MulticastIP, MulticastPort); MulticastClient = new UdpClient();
MulticastClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, false);
MulticastClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

    IPAddress ipSSDP = IPAddress.Parse(MulticastIP);                
    MulticastClient.Client.Bind(new IPEndPoint(IPAddress.Any, MulticastPort));

    logger.Info("Joining multicast group on IP [{0}]...", MulticastLocalIP);

    MulticastClient.JoinMulticastGroup(ipSSDP, IPAddress.Parse(MulticastLocalIP));
    logger.Info("2");
    running = true;

    UdpStateInfo udpListener = new UdpStateInfo(MulticastClient, new IPEndPoint(ipSSDP, MulticastPort));                
    logger.Info("Starting Multicast Receiver...");
    MulticastClient.BeginReceive(new AsyncCallback(MulticastReceiveCallback), udpListener);
    logger.Info("SSDP Service started.");
}
catch (Exception ex)
{
    logger.Warn(ex, "Error occured starting SSDP service.");
    throw ex;
}

return true;

}`

nanowebcoder commented 6 years ago

Thanks! Good call. I posted the updated code.