Functions#
This section provides a reference to the WebSocket Client API functions.
Functions#
Initialize the WebSocket client.
Connect to a WebSocket server.
Send a WebSocket frame.
Close the WebSocket connection.
Deinitialize the WebSocket client.
Extracts the WebSocket opcode from a given socket ID.
Function Documentation#
sl_websocket_init#
sl_websocket_error_t sl_websocket_init (sl_websocket_client_t * handle, const sl_websocket_config_t * config)
Initialize the WebSocket client.
[out] | handle | Pointer to the WebSocket client structure. Must not be NULL. |
[in] | config | Pointer to the WebSocket client configuration constant structure. Must not be NULL. |
This function initializes the WebSocket client with the provided configuration. It allocates necessary resources and sets up the client for connection.
Returns
sl_websocket_error_t - Error code indicating the result of the operation.
39
of file components/service/sl_websocket_client/inc/sl_websocket_client.h
sl_websocket_connect#
sl_websocket_error_t sl_websocket_connect (sl_websocket_client_t * handle)
Connect to a WebSocket server.
[in] | handle | Pointer to the WebSocket client structure. Must not be NULL. |
This function creates a socket, binds it, and connects to the specified WebSocket server.
The WebSocket handle should be initialized using sl_websocket_init before calling this function.
Returns
sl_websocket_error_t - Error code indicating the result of the operation.
56
of file components/service/sl_websocket_client/inc/sl_websocket_client.h
sl_websocket_send_frame#
sl_websocket_error_t sl_websocket_send_frame (sl_websocket_client_t * handle, const sl_websocket_send_request_t * send_request)
Send a WebSocket frame.
[in] | handle | Pointer to the WebSocket client structure. Must not be NULL. |
[in] | send_request | Pointer to the send request constant structure containing the frame details. Must not be NULL. |
This function sends a WebSocket frame to the server. Masking is taken care of by the firmware.
The WebSocket handle should be initialized using sl_websocket_init and connected using sl_websocket_connect before calling this function.
Returns
sl_websocket_error_t - Error code indicating the result of the operation.
Note
Masking refers to applying a random 32-bit mask to the data sent to the server to ensure data integrity and security.
The following table lists the maximum individual chunk of data that can be sent over each supported protocol. The length of the payload is specified in the
length
field of thesl_websocket_send_request_t
structure.
Protocol | Maximum data chunk (bytes) |
---|---|
WebSocket | 1450 bytes |
WebSocket over SSL | 1362 bytes |
86
of file components/service/sl_websocket_client/inc/sl_websocket_client.h
sl_websocket_close#
sl_websocket_error_t sl_websocket_close (sl_websocket_client_t * handle)
Close the WebSocket connection.
[in] | handle | Pointer to the WebSocket client structure. Must not be NULL. |
This function closes the WebSocket connection and cleans up resources.
The WebSocket handle should be initialized using sl_websocket_init and connected using sl_websocket_connect before calling this function.
Returns
sl_websocket_error_t - Error code indicating the result of the operation.
104
of file components/service/sl_websocket_client/inc/sl_websocket_client.h
sl_websocket_deinit#
sl_websocket_error_t sl_websocket_deinit (sl_websocket_client_t * handle)
Deinitialize the WebSocket client.
[in] | handle | Pointer to the WebSocket client structure. Must not be NULL. |
This function deinitializes the WebSocket client by freeing allocated resources and resetting the state. It should be called only after the WebSocket connection has been closed because it also attempts to close the socket as part of its cleanup process if the socket remains open after the sl_websocket_close is invoked. Therefore, calling this function is mandatory whenever a WebSocket connection is terminated, ensuring proper cleanup.
The WebSocket handle should be initialized using sl_websocket_init before calling this function.
Returns
sl_websocket_error_t - Error code indicating the result of the operation.
123
of file components/service/sl_websocket_client/inc/sl_websocket_client.h
sl_si91x_get_opcode_from_socket_id#
sl_websocket_opcode_t sl_si91x_get_opcode_from_socket_id (uint16_t socket_id)
Extracts the WebSocket opcode from a given socket ID.
[in] | socket_id | The 16-bit socket ID from which to extract the opcode. |
This function determines the opcode of the WebSocket from the socket ID. The socket_id is obtained from the recv_data_callback from the sl_si91x_socket_metadata_t parameter.
Returns
sl_websocket_opcode_t - The extracted WebSocket opcode.
138
of file components/service/sl_websocket_client/inc/sl_websocket_client.h