简体   繁体   English

Library Targetting .NET 4.5.1和Windows 8.1 / WP8.1中的套接字

[英]Sockets in Library Targetting .NET 4.5.1 and Windows 8.1/WP8.1

None of the Sockets APIs (System.Net.Sockets, System.Net.WebSockets, Windows.Networking.Sockets namespaces) exist in a PCL targetting .NET 4.5.1, Windows 8.1 and Windows Phone 8.1. 在针对.NET 4.5.1,Windows 8.1和Windows Phone 8.1的PCL中不存在任何套接字API(System.Net.Sockets,System.Net.WebSockets,Windows.Networking.Sockets命名空间)。 What are my networking options to access a input and output Stream? 访问输入和输出Stream的网络选项有哪些?

There aren't any socket API in common between the full .Net 4.5.1 Framework (using System.Net) and the Windows Runtime (using Windows.Networking). 完整的.Net 4.5.1 Framework(使用System.Net)和Windows运行时(使用Windows.Networking)之间没有任何共同的套接字API。 Since a PCL allows the intersection of the APIs for all of the PCL's targets this means there are no Socket API available directly in that PCL. 由于PCL允许所有PCL目标的API交叉,这意味着该PCL中没有直接可用的Socket API。 You'll have to open the socket in the platform specific code. 您必须在特定于平台的代码中打开套接字。

All of these targets do support .Net Streams, so once you've opened the socket in platform specific code you can pass the stream for the socket into the PCL for handling. 所有这些目标都支持.Net Streams,因此一旦您在平台特定代码中打开套接字,您就可以将套接字流传递到PCL进行处理。

You can use Inversion of Control to let the PCL request the stream from the host when necessary. 您可以使用Inversion of Control让PCL在必要时从主机请求流。 The PCL can define an interface (eg IPlatformSpecificCode) which the host can implement. PCL可以定义主机可以实现的接口(例如,IPlatformSpecificCode)。 When the PCL wants to open the network connection it can call IPlatformSpecificCode.OpenPlatformSpecificSocket(address,port) and the host can open a System.Net.Sockets.Socket or a Windows.Networking.Sockets.StreamSocket and return a .Net stream for the PCL to use. 当PCL想要打开网络连接时,它可以调用IPlatformSpecificCode.OpenPlatformSpecificSocket(地址,端口),主机可以打开System.Net.Sockets.Socket或Windows.Networking.Sockets.StreamSocket并返回.Net流PCL使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM