title: How do I connect to a websocket manually, with netcat/socat/telnet?
body: <p>I am trying to connect to the <a href="https://www.websocket.org/echo.html">reference websocket echo server</a> "manually", in order to learn how the protocol works (I am using socat for that). However, the server invariably closes the connection without providing an answer. Any idea why?</p>
  
  <p>Here is what I do:</p>
  
  <pre><code>socat - TCP:echo.websocket.org:80
  </code></pre>
  
  <p>Then, I paste the following text in the terminal:</p>
  
  <pre><code>GET /?encoding=text HTTP/1.1
  Origin: http://www.websocket.org
  Connection: Upgrade
  Host: echo.websocket.org
  Sec-WebSocket-Key: P7Kp2hTLNRPFMGLxPV47eQ==
  Upgrade: websocket
  Sec-WebSocket-Version: 13
  </code></pre>
  
  <p>I sniffed the parameters of the connection with the developer tools, in firefox, on the same machine, where this works flawlessly: therefore, I would assume they are correct. However after that, the server closes the connection immediately, without providing an answer. Why? How can I implement the protocol "manually"?</p>
  
  <p>I would like type test in my terminal and get the server to reply with what I typed (It works in a web browser).</p>