I am trying to connect to websocket api in this address : wss://ws.cex.io/ws/
If i use javascript code, with the WebSocket object, everything is fine.
If i use c# code, using ClientWebSocket class, when i try to connect i get "cant access remote server" error. with the same url i used on the js code exactly. i tried putting the url in the browser and got the same cannot reach server error, so i am pretty sure there is a header or something like this that i should use in my c# code. can anyone tell me what i am missing in my c# code ? thanks
js code (connection is made):
var ws_path = 'wss://ws.cex.io/ws';
socket = new WebSocket(ws_path);
c# code (cannot find sever)
WebSocketWrapper CexSocket = new WebSocketWrapper("wss://ws.cex.io/ws");
CexSocket.Connect();
public WebSocketWrapper(string uri)
{
_ws = new ClientWebSocket();
_ws.Options.KeepAliveInterval = TimeSpan.FromSeconds(20);
_uri = new Uri(uri);
_cancellationToken = _cancellationTokenSource.Token;
}
public WebSocketWrapper Connect()
{
ConnectAsync();
return this;
}
public WebSocketWrapper OnConnect(Action<WebSocketWrapper> onConnect)
{
_onConnected = onConnect;
return this;
}
private async void ConnectAsync()
{
await _ws.ConnectAsync(_uri, _cancellationToken); // here i get the error
CallOnConnected();
StartListen();
}