You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For more options on ``esp_websocket_client_config_t``, please refer to API reference below
66
+
.. note:: If you want to verify the server, then you need to provide a certificate in PEM format, and provide to ``cert_pem`` in :cpp:type:`websocket_client_config_t`. If no certficate is provided then the TLS connection will to default not requiring verification.
67
+
68
+
PEM certificate for this example could be extracted from an openssl `s_client` command connecting to websocket.org.
69
+
In case a host operating system has `openssl` and `sed` packages installed, one could execute the following command to download and save the root or intermediate root certificate to a file (Note for Windows users: Both Linux like environment or Windows native packages may be used).
This command will extract the second certificate in the chain and save it as a pem-file.
75
+
76
+
Subprotocol
77
+
^^^^^^^^^^^
78
+
79
+
The subprotocol field in the config struct can be used to request a subprotocol
80
+
81
+
.. code:: c
82
+
83
+
const esp_websocket_client_config_t ws_cfg = {
84
+
.uri = "ws://websocket.org",
85
+
.subprotocol = "soap",
86
+
};
87
+
88
+
.. note:: The client is indifferent to the subprotocol field in the server response and will accept the connection no matter what the server replies.
89
+
90
+
For more options on :cpp:type:`esp_websocket_client_config_t`, please refer to API reference below
91
+
92
+
Events
93
+
------
94
+
* `WEBSOCKET_EVENT_CONNECTED`: The client has successfully established a connection to the server. The client is now ready to send and receive data. Contains no event data.
95
+
* `WEBSOCKET_EVENT_DISCONNECTED`: The client has aborted the connection due to the transport layer failing to read data, e.g. because the server is unavailable. Contains no event data.
96
+
* `WEBSOCKET_EVENT_DATA`: The client has successfully received and parsed a WebSocket frame. The event data contains a pointer to the payload data, the length of the payload data as well as the opcode of the received frame. A message may be fragmented into multiple events if the length exceeds the buffer size. This event will also be posted for non-payload frames, e.g. pong or connection close frames.
97
+
* `WEBSOCKET_EVENT_ERROR`: Not used in the current implementation of the client.
98
+
99
+
If the client handle is needed in the event handler it can be accessed through the pointer passed to the event handler:
* The client is able to request the use of a subprotocol from the server during the handshake, but does not do any subprotocol related checks on the response from the server.
60
109
61
110
Application Example
62
111
-------------------
63
-
Simple WebSocket example that uses esp_websocket_client to establish a websocket connection and send/receive data with the `websocket.org <https://websocket.org>`_ Server: :example:`protocols/websocket`.
112
+
A simple WebSocket example that uses esp_websocket_client to establish a websocket connection and send/receive data with the `websocket.org <https://websocket.org>`_ server can be found here: :example:`protocols/websocket`.
113
+
114
+
Sending Text Data
115
+
^^^^^^^^^^^^^^^^^
116
+
The WebSocket client supports sending data as a text data frame, which informs the application layer that the payload data is text data encoded as UTF-8. Example:
0 commit comments