1curl_ws_send(3) libcurl curl_ws_send(3)
2
3
4
6 curl_ws_send - send WebSocket data
7
9 #include <curl/easy.h>
10
11 CURLcode curl_ws_send(CURL *curl, const void *buffer, size_t buflen,
12 size_t *sent, curl_off_t fragsize,
13 unsigned int flags);
14
16 This function call is EXPERIMENTAL.
17
18 Send the specific message fragment over an established WebSocket con‐
19 nection. The buffer holds the data to send and it is buflen number of
20 payload bytes in that memory area.
21
22 sent is returned as the number of payload bytes actually sent.
23
24 To send a (huge) fragment using multiple calls with partial content per
25 invoke, set the CURLWS_OFFSET bit and the fragsize argument as the to‐
26 tal expected size for the first part, then set the CURLWS_OFFSET with a
27 zero fragsize for the following parts.
28
29 If not sending a partial fragment or if this is raw mode, fragsize
30 should be set to zero.
31
32 If CURLWS_RAW_MODE is enabled in CURLOPT_WS_OPTIONS(3), the flags argu‐
33 ment should be set to 0.
34
35 To send a message consisting of multiple frames, set the CURLWS_CONT
36 bit in all frames except the final one.
37
39 CURLWS_TEXT
40 The buffer contains text data. Note that this makes a difference
41 to WebSocket but libcurl itself will not make any verification
42 of the content or precautions that you actually send valid UTF-8
43 content.
44
45 CURLWS_BINARY
46 This is binary data.
47
48 CURLWS_CONT
49 This is not the final fragment of the message, which implies
50 that there will be another fragment coming as part of the same
51 message where this bit is not set.
52
53 CURLWS_CLOSE
54 Close this transfer.
55
56 CURLWS_PING
57 This is a ping.
58
59 CURLWS_PONG
60 This is a pong.
61
62 CURLWS_OFFSET
63 The provided data is only a partial fragment and there will be
64 more in a following call to curl_ws_send(). When sending only a
65 piece of the fragment like this, the fragsize must be provided
66 with the total expected fragment size in the first call and it
67 needs to be zero in subsequent calls.
68
70 int ping(CURL *curl, const char *send_payload)
71 {
72 size_t sent;
73 CURLcode result =
74 curl_ws_send(curl, send_payload, strlen(send_payload), &sent, 0,
75 CURLWS_PING);
76 return (int)result;
77 }
78
80 Added in 7.86.0.
81
83 CURLE_OK (zero) means that the data was sent properly, non-zero means
84 an error occurred as <curl/curl.h> defines. See the libcurl-errors(3)
85 man page for the full list with descriptions.
86
88 curl_easy_setopt(3), curl_easy_perform(3), curl_easy_getinfo(3),
89 curl_ws_recv(3), libcurl-ws(3),
90
91
92
93libcurl 8.2.1 June 14, 2023 curl_ws_send(3)