title: Establishing a simple websocket handshake
body: <p>Client:</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
          var socket = new WebSocket('ws://localhost:8183/websession');
          socket.onopen = function () {
              alert('handshake successfully established. May send data now...');
          };
          socket.onclose = function () {
              alert('connection closed');
          };
  &lt;/script&gt;
  </code></pre>
  
  <p>server:</p>
  
  <pre><code> using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Net.Sockets;
   using System.Net;
   using System.IO;
  
  
  class Program
  {
      static void Main(string[] args)
      {
          var listener = new TcpListener(IPAddress.Loopback, 8183);
          listener.Start();
          using (var client = listener.AcceptTcpClient())
          using (var stream = client.GetStream())
          using (var reader = new StreamReader(stream))
          using (var writer = new StreamWriter(stream))
          {
              writer.WriteLine("HTTP/1.1 101 Web Socket Protocol Handshake");
              writer.WriteLine("Upgrade: WebSocket");
              writer.WriteLine("Connection: Upgrade");
              writer.WriteLine("WebSocket-Origin: http://localhost:8092");
              writer.WriteLine("WebSocket-Location: ws://localhost:8183/websession");
              writer.WriteLine("");
          }
          listener.Stop();
      }
  }
  </code></pre>
  
  <p>the problem is that the connection is never established and the onopen function is never called what may be the problem ?</p>