我有一个Windows通用应用程序应该充当TCP服务器。无法访问Windows通用应用程序内的TCP服务器
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
我已经激活的所有功能删除,作为一个可能的原因。
运行在控制台应用程序上的相同代码正常工作。
另外,运行来自 https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DatagramSocket的MS示例的结果相同。 在应用程序内部,插座是可见的,在外面,不是!
在Windows通用应用程序中运行服务器是否有任何限制,或者我缺少什么?
谢谢!
若昂
编辑我想我是不太清楚。我的问题是从外部应用程序访问TCP服务器。该应用程序可以是远程登录,Web浏览器等。服务器位于Windows通用应用程序内。
编辑#2
我花了最后一小时改变这个例子:https://ms-iot.github.io/content/en-US/win10/samples/BlinkyWebServer.htm和我的树莓派2运行它,我能够从我的计算机访问网络服务器。在我的电脑中运行相同的应用程序我无法连接。这真的很奇怪!
编辑#3我已经更改了我的应用程序,只留下了Internet(客户端&服务器)功能并且没有声明。在Raspberry Pi中运行完美无瑕,在我的本地计算机中,仍然没有运气(本地或远程)。是的,防火墙被禁用:)。根据Jared的评论,他在电脑上确认了同样的问题,这在我看来是一个错误。我会继续调查。
编辑#4了解命令“CheckNetIsolation”后,添加功能“PrivateNetworkClientServer”允许我从外部设备访问。仍然无法从本地计算机访问它(即使添加了LoopbackExempt规则)
http://stackoverflow.com/questions/17833232/cannot-connect-to-localhost-in-windows-store-application –