Kotak-Neo / kotak-neo-api

112 stars 103 forks source link

Kotak Neo WebSocket Connection in C# Fails #168

Open Pradeepmg12 opened 4 months ago

Pradeepmg12 commented 4 months ago

I am trying to connect with Kotak Neo Websocket in C# through following code, Also the websocket gets connected with the given link. but after getting connected its giving an error i,e "An exception has occured while receiving" //code : 1006 Please help me with above issue

Below is the code:-

private static void Subscribe2()
{

    ws1 = new WebSocketSharp.WebSocket(url);     //url : $"wss://mlhsm.kotaksecurities.com"
    ws1.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;   //to avoid handshake error
    ws1.OnClose += Ws_OnClose1;
    ws1.OnError += Ws_OnError1;
    ws1.OnMessage += Ws_OnMessage1;
    ws1.OnOpen += Ws_OnOpen1;
    ws1.Connect();
}
private static void Ws_OnError1(object sender, ErrorEventArgs e)
{
    Console.WriteLine("Socket error occured");
}

private static void Ws_OnClose1(object sender, CloseEventArgs e)
{
    Console.WriteLine("Socket closed");
}

private static void Ws_OnMessage1(object sender, MessageEventArgs e)
{
    Console.WriteLine("Response Received from socket");
}
private static void Ws_OnOpen1(object sender, EventArgs e)
{

    Console.WriteLine("Socket Connected to "+ url);
    dynamic obj = new ExpandoObject();            
    obj.Authorization = AccessToken;
    obj.Sid = SessionId;
    obj.type = "cn";
    ws1.Send(JsonConvert.SerializeObject(obj));
}