无法使用StreamSocket连接到TcpListener [英] Can't use StreamSocket to connect to a TcpListener
问题描述
我在移动设备上有一个应用程序,该应用程序可以连接到台式机上的服务器应用程序,我在台式机上使用TcpListener,在手机上使用TcpClient.我试图添加对Windows 8的支持,但似乎Microsoft已删除它,现在我们应该将StreamSocket用作TcpClient,将StreamSocketListener用作TcpListener.我试图更改我的代码,但它甚至都没有连接到我的TcpListener.(请注意,我也在台式机上使用了异步).
I have an app on mobile devices who connects to my server app in desktops I use TcpListener on my desktop and TcpClient on mobiles. I tried to add support for Windows 8 but it seems Microsoft removed it and now we should use StreamSocket as TcpClient and StreamSocketListener as TcpListener. I tried to change my code but it is not even connecting to my TcpListener. (Note that I used asynchronous on desktops as well).
我的桌面上的TcpListener:
TcpListener on my desktop:
server = new TcpListener(Constants.DEFAULT_PORT);
server.Start();
server.BeginAcceptSocket(new AsyncCallback(OnAccept), null);
Windows 8上的StreamSocket:
StreamSocket on my Windows 8:
var client = new StreamSocket();
await client.ConnectAsync(new EndpointPair(new HostName("localhost"), "7800", new HostName("localhost"), "7800"));
它通过ConnectAsync线路而没有连接,因为没有调用我在桌面上的OnAccept.
It passes the ConnectAsync line without being connected because my OnAccept on the desktop is not called.
所以我不知道这里出了什么问题.
So I don't know whats wrong here.
推荐答案
默认情况下,Windows运行时(存储)应用程序无法使用网络连接到本地主机.此网页对此进行了讨论: http://msdn.microsoft.com/en-us/library/windows/apps/Hh780593.aspx
By default, Windows Runtime (store) apps cannot use networking to connect to localhost. This web page talks about it: http://msdn.microsoft.com/en-us/library/windows/apps/Hh780593.aspx
我始终无法使用上述说明来进行本地主机通信,而是选择在本地网络上设置侦听器.请注意,默认情况下,甚至本地网络访问都是关闭的-您必须通过Windows Runtime应用程序的应用程序清单启用它.
I never was able to get localhost communication working using the above instructions, and opted instead to set up a listener on my local network instead. Note that even local network access is turned off by default - you have to enable it via the application manifest for the Windows Runtime app.
这篇关于无法使用StreamSocket连接到TcpListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!