title: WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake
body: <p>I have a Xamarin app that communicates using WebSocket. On the client side, I am referencing the <strong><code>ClientWebSocket</code></strong>.</p>
  
  <p>code:</p>
  
  <pre><code>using (var client = new ClientWebSocket() { Options = { KeepAliveInterval = new TimeSpan(0,0,3,0) }})
  {
      try
      {
          await client.ConnectAsync(requestUri, cancellationToken);
          do
          {
              WebSocketReceiveResult result = null;
              var buffer = new byte[ReceiveChunkSize];
              var message = new ArraySegment&lt;byte&gt;(buffer);
              do
              {
                  result = await client.ReceiveAsync(message, cancellationToken);
                  var receivedMessage = Encoding.UTF8.GetString(buffer, 0, result.Count);
                  data.Append(receivedMessage);
                  if (result.MessageType != WebSocketMessageType.Text)
                      break;
  
              } while (!result.EndOfMessage);
  
              TranslateData(data);
          } while (client.State == WebSocketState.Open &amp;&amp; !cancellationToken.IsCancellationRequested);
  </code></pre>
  
  <p>The application keeps throwing intermittently:</p>
  
  <pre><code> System.Net.WebSockets.WebSocketException (0x80004005): The remote
   party closed the WebSocket connection without completing the close
   handshake.
  </code></pre>
  
  <p>The server has a test website where it seems to function as expected. It seems the problem is on the client. The value in the <code>client.State</code> is <code>Open</code>.</p>