Skip to Content

General WebSocket - Ping and Mandatory Fields

This guide explains how to send ping messages to check that the General WebSocket connection is alive.

USE CASE

Send a ping at regular intervals and treat the connection as dead if no pong comes back.

Details

To check whether the websocket connection is alive or not, we have to send a periodically ping message. If we get a pong from websocket, it means it is alive else dead. Find how we are doing in Python Code.
Ping interval

Here there is one while loop with sleep of 10 seconds and we send a ping message to websocket to know that websocket is alive or not.

message

self.__ws_object.send("ping")

ping Type: String
value: ping (Fixed)

sleep Type: Integer
Value: 10 seconds

Good to know
  • The message is the plain text ping, not JSON. A pong reply means the connection is alive. If none comes, treat the connection as dead.
  • The sample loop sends ping and then sleeps for 10 seconds, and keeps going only while the socket is still connected.
  • The Python SDK starts this ping loop in its own thread as soon as the connection opens. If you use your own client, run the loop yourself.
  • Connection, subscribe and unsubscribe each have mandatory fields. See the table below.

Mandatory fields

MethodFieldsReason
WebSocket ConnectionWebSocket Connection URL(Endpoint)To make a connection
WebSocket ConnectionHeadersTo authorize
Subscribe Methodaction_dataTo subscribe for particular actions
Subscribe Method"SUB_T": 1While subscribing to any action
UnSubscribe Method"SUB_T": -1While unsubscribing any action
Last updated on