In general, I connected to the web socket server and I need to send a request all the time to the web socket after a certain time. Here is the method that runs when the server sends a message.
int onmessage(wsclient *c, wsclient_message *msg) { json_object *message; message = json_tokener_parse(msg->payload); json_object *t, *s; json_object_object_get_ex(message, "t", &t); json_object_object_get_ex(message, "s", &s); fprintf(stderr, "Got new event %s\n", json_object_get_string(t)); if (strcmp(json_object_get_string(t), "READY") == 0) { // Нужно хендлить именно если заголовок ивента это READY. json_object *d = json_object_object_get(message, "d"); // Число, которое нужно отправить на сервер. json_object *hb_interval = json_object_object_get(d, "heartbeat_interval"); // Интервал, с которым нужно выполнять запрос. } return 0; } At every interval of hb_interval I need to send such a JSON string to maintain connection with the server.
{ "op": 1; "d": [тут должно быть число d]; } How can this be implemented so that the program sends a heartbeat request and at the same time continues to listen to the server for requests?
I use LibWSClient and JSON-C .