I am writing a C# library for the Philips Hue Lights. I am trying to write the base API wrappers in the .NET portable set that way I can re-use this library for various platforms such as Windows 8/RT/WP. The API itself is all over HTTP using REST, so HttpWebRequest
will serve most of my needs.
The network bridge that controls the lights themselves can be discovered using SSDP over UDP. However, I am unable to find a way to use UDP sockets in the portable class library (PCL).
There is no System.Net.Sockets
available. There is nothing in the System.Net
namespace that would allow it either. I have seen a DatagramSocket
listed in Windows.Networking.Sockets
but am unable to see that namespace in Intellisense.
Does anyone have any idea how I could get UDP functionality for SSDP under the .NET PCL?
I really do not want to have to separate the discovery functionality from the core library.
Right now I am targeting .NET 4.5 + SL 5 + WP 8 + .NET for Windows Store
. I was under the impression that Sockets were available still.
NET Standard is platform-agnostic, it can run anywhere, on Windows, Mac, Linux and so on. PCLs can also run cross-platform, but they have a more limited reach. PCLs can only target a limited set of platforms.
The Portable Class Library project enables you to write and build managed assemblies that work on more than one . NET Framework platform. You can create classes that contain code you wish to share across many projects, such as shared business logic, and then reference those classes from different types of projects.
Portable Class Libraries (PCL)
A class library defines types and methods that are called by an application. If the library targets . NET Standard 2.0, it can be called by any . NET implementation (including . NET Framework) that supports .
There isn't a common intersect for socket support between WinRT and WPF apps, and so it isn't available in PCL projects targeting them.
I have a PCL library targeting WPF and WinRT that interacts with a UDP discovery network, and the cleanest implementation I came up with involved creating an IUDPSocket interface in the PCL library that defines members for sending / receiving data and connecting to multicast groups. The WPF app implements my IUDPSocket using a System.Net.Sockets.Socket, and the RT app implements this using a Windows.Networking.Sockets.DatagramSocket.
The constructor of my discovery network client class (defined in the PCL project) takes a delegate which is used to create an instance of the IUDPSocket. I do this instead of passing in an initialized IUDPSocket instance so the calling code doesn't have to know about which port(s) or address(es) are involved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With