libcurl-ws.3 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .TH libcurl 3 "10 Sep 2018" "libcurl" "libcurl"
  25. .SH NAME
  26. libcurl-ws \- WebSocket interface overview
  27. .SH DESCRIPTION
  28. The WebSocket interface provides functions for receiving and sending WebSocket
  29. data.
  30. .SH INCLUDE
  31. You still only include <curl/curl.h> in your code.
  32. .SH SETUP
  33. WebSocket is also often known as \fIWebSockets\fP, in plural. It is done by
  34. upgrading a regular HTTP(S) GET request to a WebSocket connection.
  35. WebSocket is a TCP-like message-based communication protocol done over HTTP,
  36. specified in RFC 6455.
  37. To initiate a WebSocket session with libcurl, setup an easy handle to use a
  38. URL with a "WS://" or "WSS://" scheme. "WS" is for cleartext communication
  39. over HTTP and "WSS" is for doing WebSocket securely over HTTPS.
  40. A WebSocket request is done as an HTTP/1 GET request with an "Upgrade
  41. WebSocket" request header field. When the upgrade is accepted by the server,
  42. it responds with a 101 Switching and then the client can speak WebSocket with
  43. the server. The communication can happen in both directions at the same time.
  44. .SH MESSAGES
  45. WebSocket communication is message based. That means that both ends send and
  46. receive entire messages, not streams like TCP. A WebSocket message is sent
  47. over the wire in one or more frames. Each frame in a message can have a size
  48. up to 2^63 bytes.
  49. libcurl delivers WebSocket data as frame fragments. It might send a whole
  50. frame, but it might also deliver them in pieces depending on size and network
  51. patterns. It makes sure to provide the API user about the exact specifics
  52. about the fragment: type, offset, size and how much data there is pending to
  53. arrive for the same frame.
  54. A message has an unknown size until the last frame header for the message has
  55. been received since only frames have set sizes.
  56. .SH "Raw mode"
  57. libcurl can be told to speak WebSocket in "raw mode" by setting the
  58. \fBCURLWS_RAW_MODE\fP bit to the \fICURLOPT_WS_OPTIONS(3)\fP option.
  59. Raw WebSocket means that libcurl will pass on the data from the network
  60. without parsing it leaving that entirely to the application. This mode assumes
  61. that the user of this knows WebSocket and can parse and figure out the data
  62. all by itself.
  63. This mode is intended for applications that already have a WebSocket
  64. parser/engine that want to switch over to use libcurl for enabling WebSocket,
  65. but keep parts of the existing software architecture.
  66. .SH PING
  67. WebSocket is designed to allow long-lived sessions and in order to keep the
  68. connections alive, both ends can send PING messages for the other end to
  69. respond with a PONG.
  70. libcurl automatically responds to server PING messages with a PONG. It does
  71. not send any PING messages automatically.
  72. .SH MODELS
  73. Because of the many different ways WebSocket can be used, which is much more
  74. flexible than limited to plain downloads or uploads, libcurl offers two
  75. different API models to use it:
  76. 1. Using a write callback with \fICURLOPT_WRITEFUNCTION(3)\fP much like other
  77. downloads for when the traffic is download oriented.
  78. 2. Using \fICURLOPT_CONNECT_ONLY(3)\fP and use the WebSocket recv/send
  79. functions at will.
  80. .SH "Callback model"
  81. When a write callback is set and a WebSocket transfer is performed, the
  82. callback will be called to deliver all WebSocket data that arrives.
  83. The callback can then call \fIcurl_ws_meta(3)\fP to learn about the details of
  84. the incoming data fragment.
  85. .SH "CONNECT_ONLY model"
  86. By setting \fICURLOPT_CONNECT_ONLY(3)\fP to \fB2L\fP, the transfer will only
  87. establish and setup the WebSocket communication and then return control back
  88. to the application.
  89. Once such a setup has been successfully performed, the application can proceed
  90. and use \fIcurl_ws_recv(3)\fP and \fIcurl_ws_send(3)\fP freely to exchange
  91. WebSocket messages with the server.
  92. .SH AVAILABILITY
  93. The WebSocket API was introduced as experimental in 7.86.0 and is still
  94. experimental today.
  95. It is only built-in if explicitly opted in at build time. We discourage use of
  96. the WebSocket API in production because of its experimental state. We might
  97. change API, ABI and behavior before this "goes live".
  98. .SH "SEE ALSO"
  99. .BR curl_ws_meta "(3), " curl_ws_recv "(3), " curl_ws_send "(3), "
  100. .BR curl_easy_init "(3), " CURLOPT_CONNECT_ONLY "(3), "
  101. .BR CURLOPT_WRITEFUNCTION "(3)" CURLOPT_WS_OPTIONS "(3), "