ThingWorx C SDK
|
Websocket client abstraction layer. More...
Go to the source code of this file.
Classes | |
struct | twWs |
Websocket entity structure definition. More... | |
Macros | |
#define | WS_TLS_CONN(a) (twTlsClient *)a->connection |
Typedefs | |
typedef int(* | ws_cb) (struct twWs *ws) |
typedef int(* | ws_data_cb) (struct twWs *ws, const char *at, size_t length) |
typedef struct twWs | twWs |
Websocket entity structure definition. | |
Enumerations | |
enum | close_status { SERVER_CLOSED = 0, NORMAL_CLOSE = 1000, GOING_TO_SLEEP, PROTOCOL_ERROR, UNSUPPORTED_DATA_TYPE, RESERVED1, RESERVED2, RESERVED3, INVALID_DATA, POLICY_VIOLATION, FRAME_TOO_LARGE, NO_EXTENSION_FOUND, UNEXPECTED_CONDITION } |
Websocket close reasoning enumeration. More... | |
Functions | |
int | twWs_Create (char *host, uint16_t port, char *resource, char *api_key, char *gatewayName, uint32_t messageChunkSize, uint16_t frameSize, twWs **entity) |
Creates a new websocket struct and the underlying dependent components. More... | |
int | twWs_Delete (twWs *ws) |
Frees all memory associated with a twWs structure and all its owned substructures. More... | |
int | twWs_Connect (twWs *ws, uint32_t timeout) |
Establishes a websocket connection to the server. More... | |
int | twWs_Disconnect (twWs *ws, enum close_status code, char *reason) |
Disconnect a websocket connection from the server. More... | |
char | twWs_IsConnected (twWs *ws) |
Gets the connection status of a websocket entity structure. More... | |
int | twWs_RegisterConnectCallback (twWs *ws, ws_cb cb) |
Registers a function to be called when the websocket is successfully connected. More... | |
int | twWs_RegisterCloseCallback (twWs *ws, ws_data_cb cb) |
Registers a function to be called when the websocket is closed by the server. More... | |
int | twWs_RegisterBinaryMessageCallback (twWs *ws, ws_data_cb cb) |
Registers a function to be called when the websocket receives a complete binary message. More... | |
int | twWs_RegisterTextMessageCallback (twWs *ws, ws_data_cb cb) |
Registers a function to be called when the websocket receives a complete text message. More... | |
int | twWs_RegisterPingCallback (twWs *ws, ws_data_cb cb) |
Registers a function to be called when the websocket receives a Ping message. More... | |
int | twWs_RegisterPongCallback (twWs *ws, ws_data_cb cb) |
Registers a function to be called when the websocket receives a Pong message. More... | |
int | twWs_Receive (twWs *ws, uint32_t timeout) |
Check the websocket for data and drive the state machine of the websocket. More... | |
int | twWs_SendMessage (twWs *ws, char *buf, uint32_t length, char isText) |
Send a message over the websocket. More... | |
int | twWs_SendPing (twWs *ws, char *msg) |
Send a Ping message over the websocket. More... | |
int | twWs_SendPong (twWs *ws, char *msg) |
Send a Pong message over the websocket. More... | |
Websocket client abstraction layer.
Contains structure type definitions and function prototypes for ThingWorx Websockets.
enum close_status |
Websocket close reasoning enumeration.
int twWs_Connect | ( | twWs * | ws, |
uint32_t | timeout | ||
) |
Establishes a websocket connection to the server.
[in] | ws | The twWs structure to connect. |
[in] | timeout | The amount of time (in milliseconds) to wait for the connection to be established. |
int twWs_Create | ( | char * | host, |
uint16_t | port, | ||
char * | resource, | ||
char * | api_key, | ||
char * | gatewayName, | ||
uint32_t | messageChunkSize, | ||
uint16_t | frameSize, | ||
twWs ** | entity | ||
) |
Creates a new websocket struct and the underlying dependent components.
[in] | host | The hostname of the websocket server. |
[in] | port | The port that the websocket server is listening on. |
[in] | resource | The HTTP resource to use when establishing a connection. |
[in] | api_key | The api key that will be used during an ensuing authentication process. |
[in] | gatewayName | An optional name used if the SDK is being used to develop a gateway application which allows multiple Things to connect through it. If not NULL, this is used during the binding process. |
[in] | messageChunkSize | The maximum size (in bytes) of a multipart message chunk. |
[in] | frameSize | The maximum websocket frame size (not to be confused with the maximum ThingWorx message size). |
[out] | entity | A pointer to the newly allocated twWs structure. |
entity
pointer and is responsible for freeing it via twWs_Delete().Context manipulation functions
int twWs_Delete | ( | twWs * | ws | ) |
Frees all memory associated with a twWs structure and all its owned substructures.
[in] | ws | The twWs structure to delete. |
int twWs_Disconnect | ( | twWs * | ws, |
enum close_status | code, | ||
char * | reason | ||
) |
Disconnect a websocket connection from the server.
[in] | ws | The twWs structure to disconnect. [in] code Close status code. |
[in] | reason | The reason for the disconnection. |
char twWs_IsConnected | ( | twWs * | ws | ) |
Gets the connection status of a websocket entity structure.
[in] | ws | The websocket entity structure to get the connection status of. |
ws
is connected, #FALSE if it isn't. int twWs_Receive | ( | twWs * | ws, |
uint32_t | timeout | ||
) |
Check the websocket for data and drive the state machine of the websocket.
[in] | ws | The twWs structure to utilize. |
[in] | timeout | Time (in miliseconds) to wait for data on the socket. |
int twWs_RegisterBinaryMessageCallback | ( | twWs * | ws, |
ws_data_cb | cb | ||
) |
Registers a function to be called when the websocket receives a complete binary message.
[in] | ws | The twWs structure to register with. |
[in] | cb | A pointer to the function to register. |
int twWs_RegisterCloseCallback | ( | twWs * | ws, |
ws_data_cb | cb | ||
) |
Registers a function to be called when the websocket is closed by the server.
[in] | ws | The twWs structure to register with. |
[in] | cb | A pointer to the function to register. |
int twWs_RegisterConnectCallback | ( | twWs * | ws, |
ws_cb | cb | ||
) |
Registers a function to be called when the websocket is successfully connected.
[in] | ws | The twWs structure to register with. |
[in] | cb | A pointer to the function to register. |
int twWs_RegisterPingCallback | ( | twWs * | ws, |
ws_data_cb | cb | ||
) |
Registers a function to be called when the websocket receives a Ping message.
[in] | ws | The twWs structure to register with. |
[in] | cb | A pointer to the function to register. |
int twWs_RegisterPongCallback | ( | twWs * | ws, |
ws_data_cb | cb | ||
) |
Registers a function to be called when the websocket receives a Pong message.
[in] | ws | The twWs structure to register with. |
[in] | cb | A pointer to the function to register. |
int twWs_RegisterTextMessageCallback | ( | twWs * | ws, |
ws_data_cb | cb | ||
) |
Registers a function to be called when the websocket receives a complete text message.
[in] | ws | The twWs structure to register with. |
[in] | cb | A pointer to the function to register. |
int twWs_SendMessage | ( | twWs * | ws, |
char * | buf, | ||
uint32_t | length, | ||
char | isText | ||
) |
Send a message over the websocket.
[in] | ws | The twWs structure to utilize. |
[in] | buf | A pointer to the buffer containing the message. |
[in] | length | The length of the message. |
[in] | isText | If #TRUE, will be sent as a text message, if #FALSE will be sent as a binary message. |
int twWs_SendPing | ( | twWs * | ws, |
char * | msg | ||
) |
Send a Ping message over the websocket.
[in] | ws | The twWs structure to utilize. |
[in] | msg | Less than 126 byte NULL-terminated string to send with the Ping. |
msg
data must be NULL-terminated and less than 126 bytes. int twWs_SendPong | ( | twWs * | ws, |
char * | msg | ||
) |
Send a Pong message over the websocket.
[in] | ws | The twWs structure to utilize. |
[in] | msg | Less than 126 byte NULL-terminated string to send with the Pong. |
msg
data must be NULL-terminated and less than 126 bytes.