C++ Rest SDK
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Public Member Functions | List of all members
web::websockets::client::websocket_callback_client Class Reference

Websocket client class, used to maintain a connection to a remote host for an extended session, uses callback APIs for handling receive and close event instead of async task. For some scenarios would be a alternative for the websocket_client like if you want to special handling on close event. More...

#include <ws_client.h>

Public Member Functions

_ASYNCRTIMP websocket_callback_client ()
 Creates a new websocket_callback_client. More...
 
_ASYNCRTIMP websocket_callback_client (websocket_client_config client_config)
 Creates a new websocket_callback_client. More...
 
pplx::task< void > connect (const web::uri &uri)
 Connects to the remote network destination. The connect method initiates the websocket handshake with the remote network destination, takes care of the protocol upgrade request. More...
 
pplx::task< void > send (websocket_outgoing_message msg)
 Sends a websocket message to the server . More...
 
void set_message_handler (const std::function< void(const websocket_incoming_message &msg)> &handler)
 Set the received handler for notification of client websocket messages. More...
 
pplx::task< void > close ()
 Closes a websocket client connection, sends a close frame to the server and waits for a close message from the server. More...
 
pplx::task< void > close (websocket_close_status close_status, const utility::string_t &close_reason=_XPLATSTR(""))
 Closes a websocket client connection, sends a close frame to the server and waits for a close message from the server. More...
 
void set_close_handler (const std::function< void(websocket_close_status close_status, const utility::string_t &reason, const std::error_code &error)> &handler)
 Set the closed handler for notification of client websocket closing event. More...
 
const web::uriuri () const
 Gets the websocket client URI. More...
 
const websocket_client_configconfig () const
 Gets the websocket client config object. More...
 

Detailed Description

Websocket client class, used to maintain a connection to a remote host for an extended session, uses callback APIs for handling receive and close event instead of async task. For some scenarios would be a alternative for the websocket_client like if you want to special handling on close event.

Constructor & Destructor Documentation

_ASYNCRTIMP web::websockets::client::websocket_callback_client::websocket_callback_client ( )

Creates a new websocket_callback_client.

_ASYNCRTIMP web::websockets::client::websocket_callback_client::websocket_callback_client ( websocket_client_config  client_config)

Creates a new websocket_callback_client.

Parameters
client_configThe client configuration object containing the possible configuration options to initialize the websocket_client.

Member Function Documentation

pplx::task<void> web::websockets::client::websocket_callback_client::close ( )
inline

Closes a websocket client connection, sends a close frame to the server and waits for a close message from the server.

Returns
An asynchronous operation that is completed the connection has been successfully closed.
pplx::task<void> web::websockets::client::websocket_callback_client::close ( websocket_close_status  close_status,
const utility::string_t &  close_reason = _XPLATSTR("") 
)
inline

Closes a websocket client connection, sends a close frame to the server and waits for a close message from the server.

Parameters
close_statusEndpoint MAY use the following pre-defined status codes when sending a Close frame.
close_reasonWhile closing an established connection, an endpoint may indicate the reason for closure.
Returns
An asynchronous operation that is completed the connection has been successfully closed.
const websocket_client_config& web::websockets::client::websocket_callback_client::config ( ) const
inline

Gets the websocket client config object.

Returns
A reference to the client configuration object.
pplx::task<void> web::websockets::client::websocket_callback_client::connect ( const web::uri uri)
inline

Connects to the remote network destination. The connect method initiates the websocket handshake with the remote network destination, takes care of the protocol upgrade request.

Parameters
uriThe uri address to connect.
Returns
An asynchronous operation that is completed once the client has successfully connected to the websocket server.
pplx::task<void> web::websockets::client::websocket_callback_client::send ( websocket_outgoing_message  msg)
inline

Sends a websocket message to the server .

Returns
An asynchronous operation that is completed once the message is sent.
void web::websockets::client::websocket_callback_client::set_close_handler ( const std::function< void(websocket_close_status close_status, const utility::string_t &reason, const std::error_code &error)> &  handler)
inline

Set the closed handler for notification of client websocket closing event.

Parameters
handlerThe handler for websocket closing event, It's parameters are: close_status: The pre-defined status codes used by the endpoint when sending a Close frame. reason: The reason string used by the endpoint when sending a Close frame. error: The error code if the websocket is closed with abnormal error.
void web::websockets::client::websocket_callback_client::set_message_handler ( const std::function< void(const websocket_incoming_message &msg)> &  handler)
inline

Set the received handler for notification of client websocket messages.

Parameters
handlerA function representing the incoming websocket messages handler. It's parameters are: msg: a websocket_incoming_message value indicating the message received

If this handler is not set before connecting incoming messages will be missed.

const web::uri& web::websockets::client::websocket_callback_client::uri ( ) const
inline

Gets the websocket client URI.

Returns
URI connected to.

The documentation for this class was generated from the following file: