[UWP] StreamSocketListener无法获得连接 [英] [UWP] StreamSocketListener Cannot get connection

查看:147
本文介绍了[UWP] StreamSocketListener无法获得连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想创建可以通过Socket与其他应用程序交谈的UWP应用程序,所以首先我在

https://msdn.microsoft.com/en-us/library/w89fhyex(v=vs.110).aspx

并为服务器和客户端创建2个项目,当我运行这两个客户端项目可以将数据发送到服务器。


所以现在我尝试将该代码移动到UWP App,我发现它有可用于此的StreamSocketListener。示例代码已开启 
$
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/StreamSocket

当我运行应用程序时并按照步骤 - >启动监听器 - >连接到听众 - >发送数据,示例代码工作得很好。

之后我运行C#服务器代码(控制台应用程序)并运行UWP应用程序连接到列表和发送数据。 

UWP应用程序可以毫无问题地连接和发送数据到C#服务器。


但是,如果我从UWP应用程序启动SocketListener并运行C#客户端代码(控制台应用程序),当它尝试时连接它在
上有错误


"连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接主机未能连接而建立连接失败回复127.0.0.1:2345"


请告诉我这里的错误。


谢谢你,b
Tour  ;

解决方案

Hi Tour,


我发现问题是两个应用程序(控制台和UWP) )同时访问计算机上的同一个端口,你可以尝试同时从2个不同的设备运行这两个设备并查看。



问候,


Hi,

I want to create UWP app that can talk with Other app via Socket , so first I try the normal C# code ( Console App ) on
https://msdn.microsoft.com/en-us/library/w89fhyex(v=vs.110).aspx
and create 2 project for Server and Client , when I run both of it the client project can send data to server.

So now I try to move that code to UWP App , I found that it have StreamSocketListener that can use for this . the sample code is on 
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/StreamSocket
When I run the app and follow the step on -> Start Listener -> Connect to Listener -> Send Data , the sample code work great.
After that I run C# Server code ( Console App ) and run UWP App to Connect to Lister and Send Data. 
the UWP App can connect and Send Data to C#Server without any issue.

But , If I Start SocketListener from UWP app and Run C# Client code ( Console App ) , when it try to connect it have error on

"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 127.0.0.1:2345"

Please tell me what I did wrong here.

Thank you,
Tour 

解决方案

Hi Tour,

I see the problem is both Apps (Console and UWP) are accessing the same port on the computer at same time,
you could try to run both but from 2 different devices and see.

Regards,


这篇关于[UWP] StreamSocketListener无法获得连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆