【发布时间】:2016-03-29 10:41:30
【问题描述】:
我有一个应该充当 TCP 服务器的 Windows 通用应用程序。
m_Listener = new StreamSocketListener();
m_Listener.ConnectionReceived += (s, e) => ProcessRequestAsync(e.Socket);
var bind = m_Listener.BindServiceNameAsync("8080").Wait();
在启动应用程序之前,端口没有绑定到任何东西:
C:\Users\jsant>netstat -a | grep 8080
^C (Cancelled after some seconds because no reasults were found)
然后,当我启动应用程序时:
C:\Users\jsant>netstat -a | grep 8080
TCP 0.0.0.0:8080 Laptop:0 LISTENING
所以套接字正在我的计算机上监听! 尝试以某种方式访问它会导致错误
C:\Users\jsant>telnet 127.0.0.1 8080
Connecting To 127.0.0.1...Could not open connection to the host, on port 8080: Connect failed
C:\Users\jsant>telnet 192.168.1.167 8080
Connecting To 192.168.1.167...Could not open connection to the host, on port 8080: Connect failed
C:\Users\jsant>telnet Laptop 8080
Connecting To Laptop...Could not open connection to the host, on port 8080: Connect failed
C:\Users\jsant>telnet localhost 8080
Connecting To localhost...Could not open connection to the host, on port 8080: Connect failed
我已激活所有功能以将其作为可能的原因删除。
在控制台应用程序上运行的相同代码运行良好。
另外,运行 MS 示例 https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DatagramSocket 有同样的结果。 在应用程序内部,套接字是可见的,在外部,不可见!
在 Windows 通用应用程序中运行服务器是否有任何限制,还是我遗漏了什么?
谢谢!
若昂
编辑我想我不够清楚。我的问题是从 external 应用程序访问 TCP 服务器。该应用程序可以是 telnet、Web 浏览器等。服务器位于 Windows 通用应用程序内。
编辑#2
我花了最后一个小时更改此示例:https://ms-iot.github.io/content/en-US/win10/samples/BlinkyWebServer.htm 并在我的 Raspberry Pi 2 中运行它,我能够从我的计算机访问网络服务器。在我的计算机上运行相同的应用程序,我无法连接。这真的很奇怪!
编辑 #3 我已经更改了我的应用程序,只留下了 Internet(客户端和服务器)功能,没有声明。在 Raspberry Pi 中运行完美无瑕,在我的本地计算机上,仍然没有运气(本地或远程)。是的,防火墙被禁用:)。根据 Jared 的 cmets,他确认他的计算机存在同样的问题,在我看来,这似乎是一个错误。我会继续调查。
编辑 #4 在了解命令“CheckNetIsolation”后,添加“PrivateNetworkClientServer”功能允许我从外部设备进行访问。仍然无法从本地计算机访问它(即使添加了 LoopbackExempt 规则)
【问题讨论】:
标签: win-universal-app tcpserver