Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to access TCP Server inside a Windows Universal Application

I have a Windows Universal Application that is supposed to act as a TCP server.

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

Before starting the application, the port is not bind to anything:

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

Then, when I start the application:

C:\Users\jsant>netstat -a | grep 8080
  TCP    0.0.0.0:8080           Laptop:0       LISTENING

So the socket is listening on my computer! Trying to access it somehow, results in an error

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

I have activated all the capabilities to remove that as a possible reason.

The same code running on a console application is working just fine.

Also, running the MS example from https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DatagramSocket had the same result. Inside the application the socket was visible, outside, not!

Is there any limitation of running a server in a Windows Universal Application, or am I missing something?

Thanks!

Joao

Edit I think I wasn't clear enough. My problem is accessing the TCP Server from an external application. The application can either be a telnet, web browser, etc. The server is located inside the Windows Universal App.

Edit #2
I've spent the last hour changing this example : https://ms-iot.github.io/content/en-US/win10/samples/BlinkyWebServer.htm and running it in my Raspberry Pi 2 I was able to access the webserver from my computer. Running the same application in my computer I was unable to connect. This is really strange!

Edit #3 I've changed my application, left only the Internet (Client & Server) capability and no declarations. Running in the Raspberry Pi works flawlessly, in my local computer, still no luck (local or remote). And yes, the firewall is disabled :). Based on the Jared's comments, where he confirms the same problem with his computer, this seems to me to be a bug. I'll continue to investigate.

Edit #4 after learning about the command "CheckNetIsolation", adding the capability "PrivateNetworkClientServer" allowed me to have access from an external device. Still, unable to access it from the local computer (even with a LoopbackExempt rule added)

like image 970
JoaoSantos Avatar asked Dec 23 '15 03:12

JoaoSantos


People also ask

How do I test TCP connection in Windows 10?

Press the Windows key + R, then type "cmd.exe" and click OK. Enter "telnet + IP address or hostname + port number" (e.g., telnet www.example.com 1723 or telnet 10.17. xxx. xxx 5000) to run the telnet command in Command Prompt and test the TCP port status.

What is the node js library that allows you to work with TCP Client Server?

The node:net module provides an asynchronous network API for creating stream-based TCP or IPC servers ( net. createServer() ) and clients ( net.


1 Answers

I had the same problem. This article gives a good description of the behaviour. In a nutshell, when your UWP app listens on a TCP socket and you try to connect from a non UWP app, you have to have CheckNetIsolation.exe running continuously with the -is flag like this:

CheckNetIsolation.exe LoopbackExempt -is -n=b6823a8d-d94d-4de4-b7db-4e3567ca11c8_t0fze8msm45va
like image 61
Alon Catz Avatar answered Oct 16 '22 10:10

Alon Catz