Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
858 views
in Technique[技术] by (71.8m points)

c# - Loopback Isolation Removal not working For UWP App

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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."


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...