ws_send_binary - send binary control-frame#
-
_Bool ws_send_binary(struct websockets *ws, struct ws_info *info, const char msg[], size_t msglen)#
Send a binary message of given size.
Binary messages do not need to include the null terminator (\0), they will be read up to msglen.
- Parameters:
ws – the WebSockets handle created with ws_init()
info – get information on how this transfer went
msg – the pointer to memory (linear) to send.
msglen – the length in bytes of msg.
- Returns:
true if sent, false on errors.
Example#
void on_connect(void *data,
struct websockets *ws,
struct ws_info *info,
const char *ws_protocols)
{
char text[] = "Hello from the other side";
ws_send_binary(ws, NULL, text, sizeof(text));
}
int main(void)
{
struct ws_callbacks cbs = { .on_connect = &on_connect };
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);
}