简体   繁体   English

尝试在 UWP/C# 中重新创建 Microsoft 的 .net 异步客户端/服务器套接字示例

[英]Trying to recreate Microsoft's .net Asynchronous Client/Server Socket Example in UWP/C#

I am trying to recreate Microsoft's .net examples for simple client/server communication in an c# uwp app.我正在尝试为 c# uwp 应用程序中的简单客户端/服务器通信重新创建 Microsoft 的 .net 示例。 Later on I would like to send simple data from one app to another.稍后我想将简单数据从一个应用程序发送到另一个应用程序。

Asynchronous Client Socket Example https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-client-socket-example异步客户端套接字示例https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-client-socket-example

Asynchronous Server Socket Example https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-server-socket-example异步服务器套接字示例https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-server-socket-example

I haven't made any crucial changes but modified the ipHostInfo like this:我没有做任何重要的改变,而是像这样修改了 ipHostInfo:

        IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
        ipAddress = ipHostInfo.AddressList[0];

At first I implemented client and server class in the same app which was working fine (but of course useless) .起初我在同一个应用程序中实现了客户端和服务器类,它运行良好(但当然没用)。 Now when trying to separate client and server (1 app for the client example and 1 app for server example).现在尝试分离客户端和服务器时(客户端示例有 1 个应用程序,服务器示例有 1 个应用程序)。 The client is not able to connect to server.客户端无法连接到服务器。 I successfully connected the client to some other listening ports (found in resource monitor) so problem must be the server which seams not to listen for connection requests from 'outside the own app'.我成功地将客户端连接到其他一些侦听端口(在资源监视器中找到),所以问题一定是服务器接缝不侦听来自“自己的应用程序之外”的连接请求。

In resource monitor the server-app is shown in the 'Listening Ports' list as IPv4/IPv6 loopback, TCP protocol, firewall status: allowed, not restricted.在资源监视器中,服务器应用程序在“侦听端口”列表中显示为 IPv4/IPv6 环回、TCP 协议、防火墙状态:允许,不受限制。 (tried IPv4/v6 localhost) I also added Private Networks (Client and Server) Capabilities in the manifest. (尝试了 IPv4/v6 本地主机)我还在清单中添加了专用网络(客户端和服务器)功能。 Anyone an idea what might be the problem?任何人都知道可能是什么问题?

I finally figured it out: Inbound loopbacks have to be explicitly enabled in regedit + running cmd/CheckNetIsolation.exe for UWP apps.我终于想通了:必须在 regedit + 运行 cmd/CheckNetIsolation.exe 中为 UWP 应用显式启用入站环回。 https://docs.microsoft.com/en-us/windows/iot-core/develop-your-app/loopback https://docs.microsoft.com/en-us/windows/iot-core/develop-your-app/loopback

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

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