Did not get any response form socket

aneh
Hi try to connect to server using WebSocket connection created successfully but data in response is 0. Here is my WebSocket code plz check

Method
function WebSocketTest()
{
if ("WebSocket" in window)
{
// Let us open a web socket
var ws = new WebSocket("wss://websocket.kite.trade/?api_key=&user_id=DV3508&public_token=");
ws.binaryType = "arraybuffer";
ws.onopen = function()
{
// Web Socket is connected, send data using send()
var message = {"a": "subscribe", "v": ["full", [131098372]]};
ws.send(JSON.stringify(message))
};
ws.onmessage = function (t)
{
if(t.data instanceof ArrayBuffer) {
/* if(t.data.byteLength > 2) {} */
console.log(t.data.byteLength);
}
};
ws.onclose = function()
{
// websocket is closed.
console.log("Connection is closed...");
};
}
else
{
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}
Output

Console print 1 as output
  • Kailash
    Kailash edited October 2016
    {"a": "subscribe", "v": ["full", [131098372]]}; is incorrect.

    Should be {"a": "subscribe", "v": [131098372]};
  • aneh
    aneh edited October 2016
    Hi @Kailash ,
    Now output come in this format can you plz tell me how we can get data

    [512, 11264, 1536, 314, 256, -12402, 0, 21248, 256, -13934, 10496, 14097, 768, -11903, 1280, -21738, 256, 18324, 256, -2922, 256, 26509, 256, 15249, 11264, 3328, 384, 0, -25641, 0, 5120, 0, -30505, 8960, 2170, 1024, 5858, 1280, -4841, 0, -5671, 0, -5671, 0, -4651, 0, 15065]

    Thanks
  • Kailash
    Please use one of our official libraries with streaming support (Python or NodeJS) or refer to the documentation to make your own implementation https://kite.trade/docs/connect/v1/#streaming-websocket
Sign In or Register to comment.