加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

win-universal-app – 无法访问Windows Universal Application中

发布时间:2020-12-14 02:17:57 所属栏目:Windows 来源:网络整理
导读:我有一个 Windows Universal Application应该充当TCP服务器. m_Listener = new StreamSocketListener();m_Listener.ConnectionReceived += (s,e) = ProcessRequestAsync(e.Socket);var bind = m_Listener.BindServiceNameAsync("8080").Wait(); 在启动应用程
我有一个 Windows Universal Application应该充当TCP服务器.

m_Listener = new StreamSocketListener();
m_Listener.ConnectionReceived += (s,e) => ProcessRequestAsync(e.Socket);
var bind = m_Listener.BindServiceNameAsync("8080").Wait();

在启动应用程序之前,端口没有绑定到任何东西:

C:Usersjsant>netstat -a | grep 8080
^C (Cancelled after some seconds because no reasults were found)

然后,当我启动应用程序时:

C:Usersjsant>netstat -a | grep 8080
  TCP    0.0.0.0:8080           Laptop:0       LISTENING

套接字正在我的电脑上听!
试图以某种方式访问??它会导致错误

C:Usersjsant>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:Usersjsant>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:Usersjsant>telnet Laptop 8080
Connecting To Laptop...Could not open connection to the host,on port 8080: Connect failed    
C:Usersjsant>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 Universal Application中运行服务器有任何限制,还是我遗漏了什么?

谢谢!

若昂

编辑我认为我不够清楚.我的问题是从外部应用程序访问TCP服务器.该应用程序可以是telnet,Web浏览器等.服务器位于Windows Universal App内.

编辑#2
我花了最后一小时改变这个例子:https://ms-iot.github.io/content/en-US/win10/samples/BlinkyWebServer.htm并在我的Raspberry Pi 2中运行它我能够从我的计算机访问网络服务器.在我的计算机上运行相同的应用程序我无法连接.这真奇怪!

编辑#3我已经更改了我的应用程序,只保留了Internet(客户端和服务器)功能而没有声明.在Raspberry Pi中运行完美无瑕,在我的本地计算机上,仍然没有运气(本地或远程).是的,防火墙已被禁用:).基于Jared的评论,他在计算机上确认了同样的问题,这在我看来是一个错误.我会继续调查.

在了解命令“CheckNetIsolation”后编辑#4,添加“PrivateNetworkClientServer”功能允许我从外部设备访问.仍然无法从本地计算机访问它(即使添加了LoopbackExempt规则)

解决方法

我不确定telnet是否可以连接到StreamSocketListener.我从来没有尝试过.尝试使用下面的内容,让我知道它是否有效.我稍微改变了绑定监听器的调用,因为这是我在设置中工作的方式.此外,请记住,像这样的本地网络环回将在调试中工作,但它不适用于已发布的商店应用程序.

如果它有效,您应该会看到一个消息对话框,显示已触发ConnectionReceived事件. :)希望有所帮助!

m_Listener = new StreamSocketListener();
m_Listener.ConnectionReceived += (s,e) => ProcessRequestAsync(e.Socket);
await m_Listener.BindServiceNameAsync("8080");

var ss = new StreamSocket();
await ss.ConnectAsync(new HostName("127.0.0.1"),8080);

private async void ProcessRequestAsync(StreamSocket e)
{
    await new MessageDialog("Connection received!","New Connection").ShowAsync();
    // The rest of your code goes here.
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读