I am trying to connect to WebSocket server (demo or localhost) using ClientWebSocket. I get an exception:
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
I also have JavaScript websocket client which connected succefully. Why I can't connect using ClientWebSocket?
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("Hello World!");
try
{
Console.WriteLine("Press Ctrl+C to end.");
//await ConnectAsync("ws://localhost:63762/ws");
await ConnectAsync("ws://demos.kaazing.com/echo");
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadKey();
}
}
static async Task ConnectAsync(string url)
{
using (var socket = new ClientWebSocket())
{
Console.WriteLine("---> JSON-RPC Client connecting to " + url);
await socket.ConnectAsync(new Uri(url), CancellationToken.None);
Console.WriteLine("-> Connected to web socket. Establishing JSON-RPC protocol...");
}
}
}
}