.NET可移植类库和UDP支持类库、NET、UDP

2023-09-03 15:41:15 作者:首席养猪执行官

我写了一个C#库飞利浦色调灯光。我想这样我就可以重新使用这个库的各种平台,如Windows 8 / RT / WP写基本的API包装在.NET手持话机。 API本身是各地使用REST HTTP,所以的HttpWebRequest 将成为我的大多数需求。

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.

这是控制灯本身可以使用SSDP通过UDP发现网络的桥梁。但是,我无法找到一种方法,使用UDP套接字在便携式类库(PCL)。

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).

没有的System.Net.Sockets 可用。没有任何的 System.Net 命名空间,将允许它的。我已经看到了的DatagramSocket Windows.Networking.Sockets 上市,但我无法看到在智能感知该命名空间。

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.

有没有人有任何想法如何,我可以得到UDP功能的SSDP在.NET PCL?

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.

现在我瞄准的 .NET 4.5 + SL 5 + WP 8 + .NET为Windows应用商店 的。我下的是IM pression的插座可用不动。

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.

推荐答案

没有一个共同的相交的WinRT中和WPF应用程序之间的接口支持,所以它不是用于PCL项目瞄准他们。

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.

我有针对WPF和WinRT的,与一个UDP探测网络交互的PCL库和最干净的实施,我想出了参与创建的PCL库中定义的成员发送/接收数据,并连接到多播组的IUDPSocket接口。在WPF应用程序实现了我的IUDPSocket使用System.Net.Sockets.Socket,而这种使用Windows.Networking.Sockets.DatagramSocket对RT应用程序实现。

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.

我发现网络客户端类(在PCL项目中定义)的构造函数是用来创建IUDPSocket实例的委托。我做的,而不是传递一个初始化IUDPSocket例如,这使主叫code没有知道哪个端口或地址(ES)参与。

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.