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
Content-Length: {bodyStream.Length}
Connection: close
";
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
- Connect to my intranet ip:8282
- Connect to localhost:8282
- Connect to 127.0.0.1:8282
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…