title: Creating a web server in C# UWP
body: <p>I am writing a web server as a Universal Windows Platform app in C#. Here is my code so far:</p>
  
  <pre><code>sealed partial class App : Application
      {
          int port = 8000;
  
          /// &lt;summary&gt;
          /// Initializes the singleton application object.  This is the first line of authored code
          /// executed, and as such is the logical equivalent of main() or WinMain().
          /// &lt;/summary&gt;
          public App()
          {
              StartServer();
          }
  
          private void StartServer()
          {
              StreamSocketListener listener = new StreamSocketListener();
              listener.BindServiceNameAsync(port.ToString());
              Debug.WriteLine("Bound to port: " + port.ToString());
              listener.ConnectionReceived += async (s, e) =&gt;
                  {
                      Debug.WriteLine("Got connection");
                      using (IInputStream input = e.Socket.InputStream)
                      {
                          var buffer = new Windows.Storage.Streams.Buffer(2);
                          await input.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.Partial);       
                      }
  
                      using (IOutputStream output = e.Socket.OutputStream)
                      {
                          using (Stream response = output.AsStreamForWrite())
                          {
                              response.Write(Encoding.ASCII.GetBytes("Hello, World!"), 0, 1);
                          }
                      }
                  };
          }
      }
  </code></pre>
  
  <p>I tried connecting to the server using this address:</p>
  
  <p><code>http://127.0.0.1:8000/C:/pathtohtmlfile/htmlfile.html</code></p>
  
  <p>However, the connection times out. I am not sure if it is a problem with the C# code or with something else.</p>