title: ClientWebSocket - SocketException: No connection could be made
body: <p>I am trying to connect to WebSocket server (demo or localhost) using ClientWebSocket.
  I get an exception:</p>
  <pre><code>System.Net.WebSockets.WebSocketException
    HResult=0x80004005
    Message=Unable to connect to the remote server
    Source=System.Net.WebSockets.Client
    StackTrace:
  
  Inner Exception 1:
  HttpRequestException: No connection could be made because the target machine actively refused it
  
  Inner Exception 2:
  SocketException: No connection could be made because the target machine actively refused it
  </code></pre>
  <p>I also have JavaScript websocket client which connected succefully. Why I can't connect using ClientWebSocket?</p>
  <pre><code>using System;
  using System.Net.WebSockets;
  using System.Threading;
  using System.Threading.Tasks;
  using StreamJsonRpc;
  
  namespace ConsoleApp1
  {
      class Program
      {
          static async Task Main(string[] args)
          {
              Console.WriteLine(&quot;Hello World!&quot;);
              try
              {
                  Console.WriteLine(&quot;Press Ctrl+C to end.&quot;);
                  //await ConnectAsync(&quot;ws://localhost:63762/ws&quot;);
                  await ConnectAsync(&quot;ws://demos.kaazing.com/echo&quot;);
                  
              }
              catch (Exception ex)
              {
                    Console.WriteLine(ex);
                    Console.ReadKey();
              }
          }
  
          static async Task ConnectAsync(string url)
          {
              using (var socket = new ClientWebSocket())
              {
                  Console.WriteLine(&quot;---&gt; JSON-RPC Client connecting to &quot; + url);
  
                  await socket.ConnectAsync(new Uri(url), CancellationToken.None);
                  Console.WriteLine(&quot;-&gt; Connected to web socket. Establishing JSON-RPC protocol...&quot;);
                                                           
              }
  
          }
      }
  }
  </code></pre>