WebSocket client.
More...
|
typedef struct vtm_ws_client | vtm_ws_client |
|
#define VTM_WS_CL_OPT_NO_CERT_CHECK 1 |
#define VTM_WS_CL_OPT_TIMEOUT 2 |
expects unsigned long, value is millisceonds
VTM_API vtm_ws_client* vtm_ws_client_new |
( |
void |
| ) |
|
Creates a new client.
- Returns
- the created client which can be used in the other functions
-
NULL if an error occured
VTM_API void vtm_ws_client_free |
( |
vtm_ws_client * |
cl | ) |
|
Releases the client and all allocated resources.
After this call the client pointer is no longer valid.
- Parameters
-
cl | the client that should be released |
VTM_API int vtm_ws_client_set_opt |
( |
vtm_ws_client * |
cl, |
|
|
int |
opt, |
|
|
const void * |
val, |
|
|
size_t |
len |
|
) |
| |
Sets one of the possible options.
The possible options are macros starting with VTM_WS_CL_OPT_.
- Parameters
-
cl | the client where the option should be set |
opt | the option that should be set |
val | pointer to new value of the option |
len | size of the value |
- Returns
- VTM_OK if the option was successfully set
-
VTM_E_NOT_SUPPORTED if the given option or the value format is not supported
-
VTM_ERROR if an error occured
VTM_API int vtm_ws_client_connect |
( |
vtm_ws_client * |
cl, |
|
|
enum vtm_socket_family |
fam, |
|
|
const char * |
url |
|
) |
| |
Connects to given HTTP/WebSocket server
- Parameters
-
cl | the client |
fam | the desired socket family (IPv4 or IPv6) |
url | the url where to connect to (must use http/https as scheme) |
- Returns
- VTM_OK if the client connected to the server
-
VTM_E_IO_UNKNOWN or VTM_ERROR if an error occured
VTM_API int vtm_ws_client_close |
( |
vtm_ws_client * |
cl | ) |
|
Closes the connection to the server.
- Parameters
-
cl | the client that should close the connection |
- Returns
- VTM_OK if the connection was closed successfully
-
VTM_E_IO_UNKNOWN or VTM_ERROR if an error occured
VTM_API int vtm_ws_client_send |
( |
vtm_ws_client * |
cl, |
|
|
enum vtm_ws_msg_type |
type, |
|
|
const void * |
src, |
|
|
size_t |
len |
|
) |
| |
Sends a message to the server.
- Parameters
-
cl | the client |
type | the type of the message |
src | pointer to payload of message |
len | length of payload |
- Returns
- VTM_OK if the message was successfully sent
-
VTM_E_INVALID_STATE if client is not connected to a server
-
VTM_E_IO_UNKNOWN or VTM_ERROR if an error occured
VTM_API int vtm_ws_client_recv |
( |
vtm_ws_client * |
cl, |
|
|
struct vtm_ws_msg * |
msg |
|
) |
| |
Tries to receive a message.
- Parameters
-
| cl | the client |
[out] | msg | the structure where the received message is stored |
- Returns
- VTM_OK if a message was successfully received
-
VTM_E_INVALID_STATE if client is not connected to a server
-
VTM_E_TIMEOUT if the timeout elapsed and no message was received
-
VTM_E_IO_UNKNOWN or VTM_ERROR if an error occured