websocket client does not receive any data other than the regular heartbeat of 0 bytes

sukh
I am implementing the websocket client from scratch. After the successful connection, and subscribe that returns no errors , the callback function only returns the heartbeat binary data and nothing else. I also have a python websocket client running in parallel to check if the ticks are being generated for that particular instrument token. The python client websocket returns valid ticks but my client only returns heartbeats. Is there any step that I am missing and must know.
  • sujith
    You get error messages in the text format. You need to listen to text messages to know the error.
    You might be sending a wrong subscribe message to the Kite Ticker.
  • sukh
    Earlier I had received messages about “unable to parse instrument tokens” etc as text message and I fixed them.

    Now i have no reference as to why I do not receive any ticks-no text message or otherwise.

    Is there a way to verify at the backend using logs what may be the issue with the payload ? I have no more information to proceed further from my side.
  • sukh
    Here's the output from my program. It gets connected. The subscribe and mode messages are successfully sent with no text message callback. Later, only the heartbeats follow but no ticks.


    connected!
    {"a":"subscribe","v":[738561]}
    buffer size: 0
    Successfully sent the subscribe message!
    Successfully sent the mode message! {"a":"mode","v":["full"[738561]]}
    buffer size: 0
    buffer size: 0
    buffer size: 0
    buffer size: 0
    buffer size: 0
  • sukh
    sukh edited December 2019
    @sujith Any pointer to what could be the possible cause for this issue would be helpful. The subscribe and mode messages seems to be alright and I do not get a text message back from the websocket. I am implementing a C++ client. Do you have any reference implementation for the same?
  • sujith
    The data you receive is in binary format. Can you paste your complete code here?
  • sukh
    The code is on github at the following link. I am handling the binary message and only observing text messages to figure out if there's an error.
    https://github.com/web3ninja/test_kite_ws/blob/master/kite_ws.c
  • sukh
    @sujith pls review the code and let me know if you find anything. thanks
  • sujith
    It clearly states, parsing binary data is not implemented here.
  • sukh
    sukh edited December 2019
    @sujith I have written that comment in code and I am the author of the code itself. So, I know what I am doing ! Do you see an if condition before that checks for buffer size. I receive a binary buffer of zero bytes from the web socket. If you are receiving zero bytes there’s no point of parsing that ( that’s why u see the comment there)
  • sukh
    sukh edited December 2019
    The point here is that the websocket fails silently without any valid error. This seems like some validation in kite api is not handled properly. May be a corner case, but I am hitting it. So, it may be worthwhile for you to investigate.
  • nikhilR
    Hi,
    If you follow the documentation, the length of the message can be obtained with msg.length().
    Also, streambuf isn't really required to read the message body.
    You can read the from msg.body() directly, like so:
        uint16_t num_packets = __builtin_bswap16(msg.body().read<uint16_t>().get());
    uint16_t packet_length = __builtin_bswap16(msg.body().read<uint16_t>().get());
    std::cout << "number of packets: " << num_packets << std::endl;
    std::cout << "length of packet: " << packet_length << std::endl;
    The bitswaps are done because we stream BigEndian whereas libcpprest assumes LittleEndian (atleast on my system: x86_64 GNU/Linux).

    With the above tweaks and some cleanups, I was able to parse packets successfully.

    Also, if you want people to help you, you should post a working, complete example. The file you provided has no header includes, no proper namespace conventions, no build steps and you didn't even bother mentioning which websocket library you are using.
  • sukh
    sukh edited December 2019
    @nikhilR Thank you for your help. I tested after applying the above tweaks for BigEndian and it worked. Now, I could move on to the next steps.
    For windows platform, with visual studio C++ compiler, I used _byteswap_ushort:


    uint16_t num_packets = _byteswap_ushort(msg.body().read<uint16_t>().get());
    uint16_t packet_length = _byteswap_ushort(msg.body().read<uint16_t>().get());
    std::cout << "number of packets: " << num_packets << std::endl;
    std::cout << "length of packet: " << packet_length << std::endl;</div>

This discussion has been closed.