.NET 可移植类库和 UDP 支持 [英] .NET Portable Class Library and UDP support

查看:27
本文介绍了.NET 可移植类库和 UDP 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Philips Hue Lights 编写一个 C# 库.我正在尝试在 .NET 可移植集中编写基本 API 包装器,这样我就可以将该库重新用于各种平台,例如 Windows 8/RT/WP.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 over UDP 可以发现控制灯本身的网桥.但是,我无法在可移植类库 (PCL) 中找到使用 UDP 套接字的方法.

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 命名空间中也没有任何允许它的内容.我在 Windows.Networking.Sockets 中看到了一个 DatagramSocket,但在 Intellisense 中无法看到该命名空间.

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.

有谁知道如何在 .NET PCL 下获得 SSDP 的 UDP 功能?

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 for Windows Store.我的印象是 Socket 仍然可用.

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 的 PCL 库,它与 UDP 发现网络交互,我想出的最简洁的实现涉及在 PCL 库中创建一个 IUDPSocket 接口,该接口定义用于发送/接收数据和连接到多播组的成员.WPF 应用程序使用 System.Net.Sockets.Socket 实现我的 IUDPSocket,而 RT 应用程序使用 Windows.Networking.Sockets.DatagramSocket 实现它.

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 实例,因此调用代码不必知道涉及哪些端口或地址.

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.

这篇关于.NET 可移植类库和 UDP 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆