ws_init - initialize a WebSockets handle

struct websockets *ws_init(struct ws_callbacks *cbs, CURLM *mhandle, struct ws_attr *attr)

Create a new (CURL-based) WebSockets handle.

Parameters
  • cbs – set of functions to call back when server report events.

  • mhandle – user-owned curl_multi handle for performing non-blocking transfers

  • attr – optional attributes to override defaults

Returns

newly created WebSockets handle, free with ws_cleanup()

Example

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);