Reputation: 9857
So I setup a simple StreamSocketListener
in my UWP
StreamSocketListener listener = new StreamSocketListener();
public async void StartServer()
{
await listener.BindServiceNameAsync("8282");
listener.ConnectionReceived += async (s, a) =>
{
using (var output = a.Socket.OutputStream)
{
using (var response = output.AsStreamForWrite())
{
var html = Encoding.UTF8.GetBytes(
$"<html><head><title>Background Message</title></head><body>Hello from the background process!<br/></body></html>");
using (var bodyStream = new MemoryStream(html))
{
var header = $"HTTP/1.1 200 OK\r\nContent-Length: {bodyStream.Length}\r\nConnection: close\r\n\r\n";
var headerArray = Encoding.UTF8.GetBytes(header);
await response.WriteAsync(headerArray,
0, headerArray.Length);
await bodyStream.CopyToAsync(response);
await response.FlushAsync();
}
}
}
};
}
Then, I added this to my app manifest with the package family name I got out of the gui for the package manifest.
<Extensions>
<uap4:Extension Category="windows.loopbackAccessRules">
<uap4:LoopbackAccessRules>
<uap4:Rule Direction="out" PackageFamilyName="<my package fam name>" />
<uap4:Rule Direction="in" PackageFamilyName="<my package fam name>" />
</uap4:LoopbackAccessRules>
</uap4:Extension>
</Extensions>
I went in and setup the proper capabilities
<Capability Name="privateNetworkClientServer"/>
<Capability Name="internetClientServer"/>
<uap3:Capability Name="remoteSystem"/>
<Capability Name="internetClient"/>
Finally, I enabled loopback with checknetisolation
as show in this post UWP Enable local network loopback
However, my webserver is only accessable from other devices on my network. It won't connect if I
I tried connecting from Chrome, Firefox, FireFox with a Proxy to it, and curl
I ran netstat -ano | FIND "8282"
and I can see the port is open
TCP 0.0.0.0:8282 0.0.0.0:0 LISTENING 5920
TCP [::]:8282 [::]:0 LISTENING 5920
I also tried running checknetisolation debug -n=<my package fam name>
but there was no real info in the output
Summary Report
Network Capabilities Status
----------------------------------------------------------------------
InternetClient Not Used and Insecure
InternetClientServer Not Used and Insecure
PrivateNetworkClientServer Not Used and Insecure
Detailed Traffic Report
----------------------------------------------------------------------
InternetClient Not Used and Insecure
------------------------------------------------------------------
InternetClientServer Not Used and Insecure
------------------------------------------------------------------
PrivateNetworkClientServer Not Used and Insecure
------------------------------------------------------------------
OK.
I'm at a loss of where to go now
Upvotes: 2
Views: 1098
Reputation: 1469
You are right. And to make this more clear, please see this doc for enable loopback part. Where you will see the following comments:
"Further, a Windows Runtime app can use an IP loopback only as the target address for a client network request. So a Windows Runtime app that uses a DatagramSocket or StreamSocketListener to listen on an IP loopback address is prevented from receiving any incoming packets."
Upvotes: 1