curl_ws_send.3 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. .\" generated by cd2nroff 0.1 from curl_ws_send.md
  2. .TH curl_ws_send 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_ws_send \- send WebSocket data
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_ws_send(CURL *curl, const void *buffer, size_t buflen,
  9. size_t *sent, curl_off_t fragsize,
  10. unsigned int flags);
  11. .fi
  12. .SH DESCRIPTION
  13. This function call is EXPERIMENTAL.
  14. Send the specific message fragment over an established WebSocket
  15. connection. The \fIbuffer\fP holds the data to send and it is \fIbuflen\fP
  16. number of payload bytes in that memory area.
  17. \fIsent\fP is returned as the number of payload bytes actually sent.
  18. To send a (huge) fragment using multiple calls with partial content per
  19. invoke, set the \fICURLWS_OFFSET\fP bit and the \fIfragsize\fP argument as the
  20. total expected size for the first part, then set the \fICURLWS_OFFSET\fP with
  21. a zero \fIfragsize\fP for the following parts.
  22. If not sending a partial fragment or if this is raw mode, \fIfragsize\fP
  23. should be set to zero.
  24. If \fBCURLWS_RAW_MODE\fP is enabled in \fICURLOPT_WS_OPTIONS(3)\fP, the
  25. \fBflags\fP argument should be set to 0.
  26. To send a message consisting of multiple frames, set the \fICURLWS_CONT\fP bit
  27. in all frames except the final one.
  28. .SH FLAGS
  29. .IP CURLWS_TEXT
  30. The buffer contains text data. Note that this makes a difference to WebSocket
  31. but libcurl itself does not make any verification of the content or
  32. precautions that you actually send valid UTF\-8 content.
  33. .IP CURLWS_BINARY
  34. This is binary data.
  35. .IP CURLWS_CONT
  36. This is not the final fragment of the message, which implies that there is
  37. another fragment coming as part of the same message where this bit is not set.
  38. .IP CURLWS_CLOSE
  39. Close this transfer.
  40. .IP CURLWS_PING
  41. This is a ping.
  42. .IP CURLWS_PONG
  43. This is a pong.
  44. .IP CURLWS_OFFSET
  45. The provided data is only a partial fragment and there is more coming in a
  46. following call to \fIcurl_ws_send()\fP. When sending only a piece of the
  47. fragment like this, the \fIfragsize\fP must be provided with the total
  48. expected fragment size in the first call and it needs to be zero in subsequent
  49. calls.
  50. .SH PROTOCOLS
  51. This functionality affects ws only
  52. .SH EXAMPLE
  53. .nf
  54. #include <string.h> /* for strlen */
  55. const char *send_payload = "magic";
  56. int main(void)
  57. {
  58. size_t sent;
  59. CURLcode res;
  60. CURL *curl = curl_easy_init();
  61. curl_easy_setopt(curl, CURLOPT_URL, "wss://example.com/");
  62. curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L);
  63. curl_easy_perform(curl);
  64. res = curl_ws_send(curl, send_payload, strlen(send_payload), &sent, 0,
  65. CURLWS_PING);
  66. curl_easy_cleanup(curl);
  67. return (int)res;
  68. }
  69. .fi
  70. .SH AVAILABILITY
  71. Added in curl 7.86.0
  72. .SH RETURN VALUE
  73. \fICURLE_OK\fP (zero) means that the data was sent properly, non\-zero means an
  74. error occurred as \fI<curl/curl.h>\fP defines. See the \fIlibcurl\-errors(3)\fP man
  75. page for the full list with descriptions.
  76. .SH SEE ALSO
  77. .BR curl_easy_getinfo (3),
  78. .BR curl_easy_perform (3),
  79. .BR curl_easy_setopt (3),
  80. .BR curl_ws_recv (3),
  81. .BR libcurl-ws (3)