Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
web_socket.h File Reference
WebSocket API (client and server) More...
Go to the source code of this file.
Data Structures | |
struct | WebSocketAuthContext |
Authentication context. More... | |
struct | WebSocketHandshakeContext |
Handshake context. More... | |
struct | WebSocketFrameContext |
Frame encoding/decoding context. More... | |
struct | WebSocketUtf8Context |
UTF-8 decoding context. More... | |
struct | _WebSocket |
Structure describing a WebSocket. More... | |
Typedefs | |
typedef error_t(* | WebSocketRandCallback )(uint8_t *data, size_t length) |
Random data generation callback function. | |
typedef error_t(* | WebSocketTlsInitCallback )(WebSocket *webSocket, TlsContext *tlsContext) |
SSL/TLS initialization callback function. | |
Enumerations | |
enum | WebSocketEndpoint |
WebSocket endpoint types. More... | |
enum | WebSocketHttpVersion |
HTTP version numbers. More... | |
enum | WebSocketAuthMode |
Authentication schemes. More... | |
enum | WebSocketState |
WebSocket states. More... | |
enum | WebSocketSubState |
WebSocket sub-states. More... | |
enum | WebSocketFrameType |
WebSocket frame types. More... | |
enum | WebSocketStatusCode |
WebSocket status codes. More... | |
Functions | |
error_t | webSocketInit (void) |
WebSocket related initialization. | |
error_t | webSocketRegisterRandCallback (WebSocketRandCallback callback) |
Register RNG callback function. | |
WebSocket * | webSocketOpen (void) |
Create a WebSocket. | |
WebSocket * | webSocketUpgradeSocket (Socket *socket) |
Upgrade a socket to a WebSocket. | |
WebSocket * | webSocketUpgradeSecureSocket (Socket *socket, TlsContext *tlsContext) |
Upgrade a secure socket to a secure WebSocket. | |
error_t | webSocketRegisterTlsInitCallback (WebSocket *webSocket, WebSocketTlsInitCallback callback) |
Register TLS initialization callback function. | |
error_t | webSocketSetTimeout (WebSocket *webSocket, systime_t timeout) |
Set timeout value for blocking operations. | |
error_t | webSocketSetHost (WebSocket *webSocket, const char_t *host) |
Set the hostname of the resource being requested. | |
error_t | webSocketSetOrigin (WebSocket *webSocket, const char_t *origin) |
Set the origin header field. | |
error_t | webSocketSetSubProtocol (WebSocket *webSocket, const char_t *subProtocol) |
Set the sub-protocol header field. | |
error_t | webSocketSetAuthInfo (WebSocket *webSocket, const char_t *username, const char_t *password, uint_t allowedAuthModes) |
Set authentication information. | |
error_t | webSocketBindToInterface (WebSocket *webSocket, NetInterface *interface) |
Bind the WebSocket to a particular network interface. | |
error_t | webSocketConnect (WebSocket *webSocket, const IpAddr *serverIpAddr, uint16_t serverPort, const char_t *uri) |
Establish a WebSocket connection. | |
error_t | webSocketSetClientKey (WebSocket *webSocket, const char_t *clientKey) |
Set client's key. | |
error_t | webSocketParseClientHandshake (WebSocket *webSocket) |
Parse client's handshake. | |
error_t | webSocketSendServerHandshake (WebSocket *webSocket) |
Send server's handshake. | |
error_t | webSocketSendErrorResponse (WebSocket *webSocket, uint_t statusCode, const char_t *message) |
Send HTTP error response to the client. | |
error_t | webSocketSend (WebSocket *webSocket, const void *data, size_t length, WebSocketFrameType type, size_t *written) |
Transmit data over the WebSocket connection. | |
error_t | webSocketSendEx (WebSocket *webSocket, const void *data, size_t length, WebSocketFrameType type, size_t *written, bool_t firstFrag, bool_t lastFrag) |
Transmit data over the WebSocket connection. | |
error_t | webSocketReceive (WebSocket *webSocket, void *data, size_t size, WebSocketFrameType *type, size_t *received) |
Receive data from a WebSocket connection. | |
error_t | webSocketReceiveEx (WebSocket *webSocket, void *data, size_t size, WebSocketFrameType *type, size_t *received, bool_t *firstFrag, bool_t *lastFrag) |
Receive data from a WebSocket connection. | |
bool_t | webSocketIsRxReady (WebSocket *webSocket) |
Check whether some data is available in the receive buffer. | |
error_t | webSocketShutdown (WebSocket *webSocket) |
Gracefully close a WebSocket connection. | |
void | webSocketClose (WebSocket *webSocket) |
Close a WebSocket connection. |
Detailed Description
WebSocket API (client and server)
License
Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
This file is part of CycloneTCP Open.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- Version:
- 1.7.6
Definition in file web_socket.h.
Typedef Documentation
typedef error_t(* WebSocketRandCallback)(uint8_t *data, size_t length) |
Random data generation callback function.
Definition at line 326 of file web_socket.h.
typedef error_t(* WebSocketTlsInitCallback)(WebSocket *webSocket, TlsContext *tlsContext) |
SSL/TLS initialization callback function.
Definition at line 336 of file web_socket.h.
Enumeration Type Documentation
enum WebSocketAuthMode |
Authentication schemes.
Definition at line 205 of file web_socket.h.
enum WebSocketEndpoint |
WebSocket endpoint types.
Definition at line 182 of file web_socket.h.
enum WebSocketFrameType |
WebSocket frame types.
Definition at line 255 of file web_socket.h.
enum WebSocketHttpVersion |
HTTP version numbers.
Definition at line 193 of file web_socket.h.
enum WebSocketState |
WebSocket states.
Definition at line 217 of file web_socket.h.
enum WebSocketStatusCode |
WebSocket status codes.
Definition at line 270 of file web_socket.h.
enum WebSocketSubState |
WebSocket sub-states.
Definition at line 237 of file web_socket.h.
Function Documentation
error_t webSocketBindToInterface | ( | WebSocket * | webSocket, |
NetInterface * | interface | ||
) |
Bind the WebSocket to a particular network interface.
- Parameters:
-
[in] webSocket Handle to a WebSocket [in] interface Network interface to be used
- Returns:
- Error code
Definition at line 364 of file web_socket.c.
void webSocketClose | ( | WebSocket * | webSocket ) |
Close a WebSocket connection.
- Parameters:
-
[in] webSocket Handle identifying the WebSocket to close
Definition at line 1539 of file web_socket.c.
error_t webSocketConnect | ( | WebSocket * | webSocket, |
const IpAddr * | serverIpAddr, | ||
uint16_t | serverPort, | ||
const char_t * | uri | ||
) |
Establish a WebSocket connection.
- Parameters:
-
[in] webSocket Handle to a WebSocket [in] serverIpAddr IP address of the WebSocket server to connect to [in] serverPort TCP port number that will be used to establish the connection [in] uri NULL-terminated string that contains the resource name
- Returns:
- Error code
Definition at line 388 of file web_socket.c.
error_t webSocketInit | ( | void | ) |
bool_t webSocketIsRxReady | ( | WebSocket * | webSocket ) |
Check whether some data is available in the receive buffer.
- Parameters:
-
[in] webSocket Handle to a WebSocket
- Returns:
- The function returns TRUE if some data is pending and can be read immediately without blocking. Otherwise, FALSE is returned
Definition at line 1398 of file web_socket.c.
WebSocket* webSocketOpen | ( | void | ) |
Create a WebSocket.
- Returns:
- Handle referencing the new WebSocket
Definition at line 93 of file web_socket.c.
error_t webSocketParseClientHandshake | ( | WebSocket * | webSocket ) |
Parse client's handshake.
- Parameters:
-
[in] webSocket Handle that identifies a WebSocket
- Returns:
- Error code
Definition at line 708 of file web_socket.c.
error_t webSocketReceive | ( | WebSocket * | webSocket, |
void * | data, | ||
size_t | size, | ||
WebSocketFrameType * | type, | ||
size_t * | received | ||
) |
Receive data from a WebSocket connection.
- Parameters:
-
[in] webSocket Handle that identifies a WebSocket [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [out] type Frame type [out] received Number of bytes that have been received
- Returns:
- Error code
Definition at line 1120 of file web_socket.c.
error_t webSocketReceiveEx | ( | WebSocket * | webSocket, |
void * | data, | ||
size_t | size, | ||
WebSocketFrameType * | type, | ||
size_t * | received, | ||
bool_t * | firstFrag, | ||
bool_t * | lastFrag | ||
) |
Receive data from a WebSocket connection.
- Parameters:
-
[in] webSocket Handle that identifies a WebSocket [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [out] type Frame type [out] received Number of bytes that have been received [out] firstFrag First fragment of the message [out] lastFrag Last fragment of the message
- Returns:
- Error code
Definition at line 1143 of file web_socket.c.
error_t webSocketRegisterRandCallback | ( | WebSocketRandCallback | callback ) |
Register RNG callback function.
- Parameters:
-
[in] callback RNG callback function
- Returns:
- Error code
Definition at line 74 of file web_socket.c.
error_t webSocketRegisterTlsInitCallback | ( | WebSocket * | webSocket, |
WebSocketTlsInitCallback | callback | ||
) |
Register TLS initialization callback function.
- Parameters:
-
[in] webSocket Handle that identifies a WebSocket [in] callback TLS initialization callback function
- Returns:
- Error code
Definition at line 217 of file web_socket.c.
error_t webSocketSend | ( | WebSocket * | webSocket, |
const void * | data, | ||
size_t | length, | ||
WebSocketFrameType | type, | ||
size_t * | written | ||
) |
Transmit data over the WebSocket connection.
- Parameters:
-
[in] webSocket Handle that identifies a WebSocket [in] data Pointer to a buffer containing the data to be transmitted [in] length Number of data bytes to send [in] type Frame type [out] written Actual number of bytes written (optional parameter)
- Returns:
- Error code
Definition at line 935 of file web_socket.c.
error_t webSocketSendErrorResponse | ( | WebSocket * | webSocket, |
uint_t | statusCode, | ||
const char_t * | message | ||
) |
Send HTTP error response to the client.
- Parameters:
-
[in] webSocket Handle that identifies a WebSocket [in] statusCode HTTP status code [in] message Text message
- Returns:
- Error code
Definition at line 860 of file web_socket.c.
error_t webSocketSendEx | ( | WebSocket * | webSocket, |
const void * | data, | ||
size_t | length, | ||
WebSocketFrameType | type, | ||
size_t * | written, | ||
bool_t | firstFrag, | ||
bool_t | lastFrag | ||
) |
Transmit data over the WebSocket connection.
- Parameters:
-
[in] webSocket Handle that identifies a WebSocket [in] data Pointer to a buffer containing the data to be transmitted [in] length Number of data bytes to send [in] type Frame type [out] written Actual number of bytes written (optional parameter) [in] firstFrag First fragment of the message [in] lastFrag Last fragment of the message
Definition at line 956 of file web_socket.c.
error_t webSocketSendServerHandshake | ( | WebSocket * | webSocket ) |
Send server's handshake.
- Parameters:
-
[in] webSocket Handle that identifies a WebSocket
- Returns:
- Error code
Definition at line 797 of file web_socket.c.
error_t webSocketSetAuthInfo | ( | WebSocket * | webSocket, |
const char_t * | username, | ||
const char_t * | password, | ||
uint_t | allowedAuthModes | ||
) |
Set authentication information.
- Parameters:
-
[in] webSocket Handle to a WebSocket [in] username NULL-terminated string containing the user name to be used [in] password NULL-terminated string containing the password to be used [in] allowedAuthModes Logic OR of allowed HTTP authentication modes
- Returns:
- Error code
Definition at line 331 of file web_socket.c.
error_t webSocketSetClientKey | ( | WebSocket * | webSocket, |
const char_t * | clientKey | ||
) |
Set client's key.
- Parameters:
-
[in] webSocket Handle to a WebSocket [in] clientKey NULL-terminated string that holds the the client's key
- Returns:
- Error code
Definition at line 642 of file web_socket.c.
error_t webSocketSetHost | ( | WebSocket * | webSocket, |
const char_t * | host | ||
) |
Set the hostname of the resource being requested.
- Parameters:
-
[in] webSocket Handle to a WebSocket [in] host NULL-terminated string containing the hostname
- Returns:
- Error code
Definition at line 266 of file web_socket.c.
error_t webSocketSetOrigin | ( | WebSocket * | webSocket, |
const char_t * | origin | ||
) |
Set the origin header field.
- Parameters:
-
[in] webSocket Handle to a WebSocket [in] origin NULL-terminated string containing the origin
- Returns:
- Error code
Definition at line 287 of file web_socket.c.
error_t webSocketSetSubProtocol | ( | WebSocket * | webSocket, |
const char_t * | subProtocol | ||
) |
Set the sub-protocol header field.
- Parameters:
-
[in] webSocket Handle to a WebSocket [in] subProtocol NULL-terminated string containing the sub-protocol
- Returns:
- Error code
Definition at line 308 of file web_socket.c.
error_t webSocketSetTimeout | ( | WebSocket * | webSocket, |
systime_t | timeout | ||
) |
Set timeout value for blocking operations.
- Parameters:
-
[in] webSocket Handle to a WebSocket [in] timeout Maximum time to wait
- Returns:
- Error code
Definition at line 241 of file web_socket.c.
error_t webSocketShutdown | ( | WebSocket * | webSocket ) |
Gracefully close a WebSocket connection.
- Parameters:
-
[in] webSocket Handle to a WebSocket
Definition at line 1423 of file web_socket.c.
WebSocket* webSocketUpgradeSecureSocket | ( | Socket * | socket, |
TlsContext * | tlsContext | ||
) |
Upgrade a secure socket to a secure WebSocket.
- Parameters:
-
[in] socket Handle referencing the socket [in] tlsContext Pointer to the SSL/TLS context
- Returns:
- Handle referencing the new WebSocket
Definition at line 178 of file web_socket.c.
WebSocket* webSocketUpgradeSocket | ( | Socket * | socket ) |
Upgrade a socket to a WebSocket.
- Parameters:
-
[in] socket Handle referencing the socket
- Returns:
- Handle referencing the new WebSocket
Definition at line 139 of file web_socket.c.
Generated on Tue Jul 12 2022 17:10:23 by
