Giri's C++ Support Library
C++ library providing everything you need to quickly create awesome applications.
giri::WebSocketSession Class Reference

Class representing one session/connection. More...

#include <WebSocketServer.h>

Inheritance diagram for giri::WebSocketSession:
Collaboration diagram for giri::WebSocketSession:

Public Types

using SPtr = std::shared_ptr< WebSocketSession >
 
using UPtr = std::unique_ptr< WebSocketSession >
 
using WPtr = std::weak_ptr< WebSocketSession >
 
- Public Types inherited from giri::Object< T >
using SPtr = std::shared_ptr< T >
 
using UPtr = std::unique_ptr< T >
 
using WPtr = std::weak_ptr< T >
 

Public Member Functions

 WebSocketSession (tcp::socket socket, bool ssl, const std::filesystem::path &cert, const std::filesystem::path &key, boost::asio::io_context &ioc)
 
void run ()
 
void send (const std::string &msg)
 msg Message to send More...
 
std::string getMessage () const
 
bool getSSL () const
 
boost::system::error_code getError () const
 
std::string getClientIP () const
 
std::string getClientPort () const
 
void close ()
 
- Public Member Functions inherited from giri::Observable< WebSocketSession >
void subscribe (const std::weak_ptr< Observer< WebSocketSession > > &obs)
 
void unsubscribe (const std::weak_ptr< Observer< WebSocketSession > > &obs)
 
void unsubscribeAll ()
 
void notify ()
 

Detailed Description

Class representing one session/connection.

Created by the server when accepting a client connection.

Constructor & Destructor Documentation

◆ WebSocketSession()

giri::WebSocketSession::WebSocketSession ( tcp::socket  socket,
bool  ssl,
const std::filesystem::path &  cert,
const std::filesystem::path &  key,
boost::asio::io_context &  ioc 
)
inlineexplicit

WebSocketSession constructor

Parameters
socketSocket to use.
ssltrue if ssl should be enabled, false otherwise.
certIf ssl is true, path to certificate file in *.pem format.
keyIf ssl is true path to private key file in *pem format.
iocI/O context which should be used.

Member Function Documentation

◆ close()

void giri::WebSocketSession::close ( )
inline

Close websocket session.

◆ getClientIP()

std::string giri::WebSocketSession::getClientIP ( ) const
inline
Returns
IP of connected client.

◆ getClientPort()

std::string giri::WebSocketSession::getClientPort ( ) const
inline
Returns
Port of connected client.

◆ getError()

boost::system::error_code giri::WebSocketSession::getError ( ) const
inline
Returns
Error code if last request was not successful.

◆ getMessage()

std::string giri::WebSocketSession::getMessage ( ) const
inline
Returns
last received message.

◆ getSSL()

bool giri::WebSocketSession::getSSL ( ) const
inline
Returns
true if ssl is enabled, false otherwise.

◆ run()

void giri::WebSocketSession::run ( )
inline

Starts receiving messages asynchrolously. Automatically notifies subscribed Observer objects on new messages.

◆ send()

void giri::WebSocketSession::send ( const std::string &  msg)
inline

msg Message to send

Send a message to the client, this session is associated with. Blocks until message was sent.


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