ws_pong - send PONG control-frame

_Bool ws_pong(struct websockets *ws, struct ws_info *info, const char reason[], size_t len)

Send a PONG (opcode 0xA) frame with reason as payload.

Note that pong is sent automatically if no “on_ping” callback is defined. If one is defined you must send pong manually.

Parameters
  • ws – the WebSockets handle created with ws_init()

  • info – get information on how this transfer went

  • reason – NULL or some UTF-8 string null (‘\0’) terminated.

  • len – the length of reason in bytes. If SIZE_MAX, uses strlen() on reason if it’s not NULL.

Returns

true if sent, false on errors.

Example

void on_ping(void *data,
             struct websockets *ws,
             struct ws_info *info,
             const char reason[],
             size_t len)
{
  char reason[] = "Who's there?";

  ws_pong(ws, NULL, reason, sizeof(reason));
}

int main(void)
{
  struct ws_callbacks cbs = { .on_ping = &on_ping };
  CURLM *mhandle = curl_multi_init();
  struct websockets *ws = ws_init(&cbs, mhandle, NULL);
  ws_set_url(ws, "wss://example.com", NULL);

  /* run the event-loop */
  ws_start(ws);

  uint64_t tstamp;
  bool is_running;
  do {
    is_running = ws_easy_run(ws, 5, &tstamp);
  } while (is_running);

  ws_end(ws);

  ws_cleanup(ws);
  curl_multi_cleanup(mhandle);
}