Unable to access TCP server in universal Windows application

I have a universal Windows application that should 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 attached to anything:

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

Then, when I launch 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 leads to 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 features to remove this as a possible reason.

The same code running in the console application works 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 restriction on starting the server in a universal Windows application, or am I missing something?

Thanks!

Joao

Edit I think that I was not clear enough. My problem is accessing the TCP server from an external application. The application may be telnet, web browser, etc. The server is inside a universal Windows application.

Edit # 2
I spent the last hour changing this example: https://ms-iot.imtqy.com/content/en-US/win10/samples/BlinkyWebServer.htm and ran it in my Raspberry Pi 2. I was able to access the web to the server from my computer. Running the same application on my computer, I was unable to connect. This is really weird!

Change # 3 I changed my application, left only Internet features (client and server) and no ads. Work in Raspberry Pi works flawlessly, on my local computer, still not luck (local or remote). And yes, the firewall is disabled :). Based on the comments of Jared, where he confirms the same problem with his computer, it seems to me that this is a mistake. I will continue the investigation.

Edit # 4 after learning the "CheckNetIsolation" command, adding the "PrivateNetworkClientServer" option to allow me access from an external device. However, it was not possible to access it from the local computer (even when adding the LoopbackExempt rule)

+5
source share
3 answers

I'm not sure that telnet even works to connect to StreamSocketListener. I have never tried this. Try using below and let me know if this works. I changed the call a bit to tie the listener, since this is how I work in my setup. Also, keep in mind that a LAN loop like this one will work in debugging, but it will not work for published store apps.

If this works, you should get a dialog box informing you that the ConnectionReceived event has been triggered. :) Hope this helps!

 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. } 
0
source

Have you tried incorporating the private network feature into your UWP? I use it for a similar project.

I think you need this feature if you want to manage a local network connection.

0
source

Allow LAN loop in "Project → Properties → Debugging → Allow LAN loop".

0
source

Source: https://habr.com/ru/post/1239003/


All Articles