0

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 on my desktop:

server = new TcpListener(Constants.DEFAULT_PORT);

server.Start();

server.BeginAcceptSocket(new AsyncCallback(OnAccept), null);

StreamSocket on my Windows 8:

var client = new StreamSocket();
await client.ConnectAsync(new EndpointPair(new HostName("localhost"), "7800", new HostName("localhost"), "7800"));

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.

Peyman
  • 3,059
  • 1
  • 33
  • 68

1 Answers1

2

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

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.

chue x
  • 18,573
  • 7
  • 56
  • 70
  • It should also be pointed out that even by using the instructions in the link provided (not that I have tried) communication to another process on localhost is allowed only for development purposes, i.e. in Visual Studio. – Damir Arh Nov 16 '12 at 05:43
  • You can find the solution in this other SO question: http://stackoverflow.com/questions/7465517/how-can-a-metro-app-in-windows-8-communicate-with-a-backend-desktop-app-on-the-s – adosaiguas May 15 '14 at 13:50