# AsyncWebSocket.hpp
This File On Github
Ask A Question
API: latest
module: oatpp-websocket
#include "oatpp-websocket/AsyncWebSocket.hpp"
# AsyncWebSocket
Asynchronous WebSocket.
namespace oatpp { namespace websocket {
class AsyncWebSocket : public oatpp::base::Countable, public std::enable_shared_from_this<AsyncWebSocket> {}
}}
# Typedefs
Type | Name | Summary |
---|---|---|
oatpp::async::Action | Action | Convenience typedef for oatpp::async::Action. |
oatpp::async::CoroutineStarter | CoroutineStarter | Convenince typedef for oatpp::async::CoroutineStarter. |
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | AsyncWebSocket | Multiple implementations:
|
std::shared_ptr<AsyncWebSocket> | createShared | Multiple implementations:
|
void | setConfig | Set WebSocket config. |
provider::ResourceHandle<oatpp::data::stream::IOStream> | getConnection | Get socket connection. |
void | setListener | Set socket event listener. |
std::shared_ptr<Listener> | getListener | Get socket event listener |
CoroutineStarter | listenAsync | Start listening Coroutine. |
CoroutineStarter | writeFrameHeaderAsync | Send custom frame to peer. |
CoroutineStarter | sendFrameHeaderAsync | Send default frame to peer with fin, opcode and messageSize set. |
CoroutineStarter | sendOneFrameAsync | Send one frame message with custom fin and opcode. |
CoroutineStarter | sendCloseAsync | Multiple implementations:
|
CoroutineStarter | sendPingAsync | Send ping frame. |
CoroutineStarter | sendPongAsync | Send pong frame. |
CoroutineStarter | sendOneFrameTextAsync | Send one frame text message. |
CoroutineStarter | sendOneFrameBinaryAsync | Send one frame binary message. |
# AsyncWebSocket::Action
Convenience typedef for oatpp::async::Action.
typedef oatpp::async::Action Action
# AsyncWebSocket::CoroutineStarter
Convenince typedef for oatpp::async::CoroutineStarter.
typedef oatpp::async::CoroutineStarter CoroutineStarter
# AsyncWebSocket::AsyncWebSocket
- Constructor with Config.
- @param connection - oatpp::data::stream::IOStream.
- @param config - oatpp::websocket::Config.
AsyncWebSocket(const provider::ResourceHandle<oatpp::data::stream::IOStream>& connection, const Config& config)
- Constructor.
- @param connection - oatpp::data::stream::IOStream.
- @param maskOutgoingMessages - for servers should be
false
. For clients should betrue
.
AsyncWebSocket(const provider::ResourceHandle<oatpp::data::stream::IOStream>& connection, bool maskOutgoingMessages)
- Deleted copy-constructor.
AsyncWebSocket(const AsyncWebSocket&) = delete
# AsyncWebSocket::createShared
- Create shared AsyncWebSocket with Config.
- @param connection - oatpp::data::stream::IOStream.
- @param config - oatpp::websocket::Config.
- @return -
std::shared_ptr
to AsyncWebSocket.
static std::shared_ptr<AsyncWebSocket> createShared(const provider::ResourceHandle<oatpp::data::stream::IOStream>& connection, const Config& config)
- Create shared AsyncWebSocket.
- @param connection - oatpp::data::stream::IOStream.
- @param maskOutgoingMessages - for servers should be
false
. For clients should betrue
. - @return -
std::shared_ptr
to AsyncWebSocket.
static std::shared_ptr<AsyncWebSocket> createShared(const provider::ResourceHandle<oatpp::data::stream::IOStream>& connection, bool maskOutgoingMessages)
# AsyncWebSocket::setConfig
Set WebSocket config.
- @param config - oatpp::websocket::Config.
void setConfig(const Config& config)
# AsyncWebSocket::getConnection
Get socket connection.
- @return - oatpp::data::stream::IOStream.
provider::ResourceHandle<oatpp::data::stream::IOStream> getConnection() const
# AsyncWebSocket::setListener
Set socket event listener.
- @param listener - AsyncWebSocket::Listener.
void setListener(const std::shared_ptr<Listener>& listener)
# AsyncWebSocket::getListener
Get socket event listener
- @return - AsyncWebSocket::Listener.
std::shared_ptr<Listener> getListener()
# AsyncWebSocket::listenAsync
Start listening Coroutine.
Read incoming frames and call corresponding methods of listener. See AsyncWebSocket::setListener().
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter listenAsync()
# AsyncWebSocket::writeFrameHeaderAsync
Send custom frame to peer.
Use this method if you know what you are doing.
- @param frameHeader - oatpp::websocket::Frame::Header.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter writeFrameHeaderAsync(const std::shared_ptr<Frame::Header>& frameHeader)
# AsyncWebSocket::sendFrameHeaderAsync
Send default frame to peer with fin, opcode and messageSize set.
Use this method if you know what you are doing.
- @param frameHeader - oatpp::websocket::Frame::Header.
- @param fin - FIN bit.
- @param opcode - operation code. See oatpp::websocket::Frame::Header.
- @param messageSize - size of the coming message.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter sendFrameHeaderAsync(const std::shared_ptr<Frame::Header>& frameHeader, bool fin, v_uint8 opcode, v_int64 messageSize)
# AsyncWebSocket::sendOneFrameAsync
Send one frame message with custom fin and opcode.
- @param fin - FIN bit.
- @param opcode - operation code. See oatpp::websocket::Frame::Header.
- @param message - message text. oatpp::String.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter sendOneFrameAsync(bool fin, v_uint8 opcode, const oatpp::String& message)
# AsyncWebSocket::sendCloseAsync
- Send close frame.
- @param code - code of the websocket connection close message.
- @param message - message text. oatpp::String.
- @return - oatpp::async::Action.
CoroutineStarter sendCloseAsync(v_uint16 code, const oatpp::String& message)
- Send close frame without message.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter sendCloseAsync()
# AsyncWebSocket::sendPingAsync
Send ping frame.
- @param message - message text. oatpp::String.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter sendPingAsync(const oatpp::String& message)
# AsyncWebSocket::sendPongAsync
Send pong frame.
- @param message - message text. oatpp::String.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter sendPongAsync(const oatpp::String& message)
# AsyncWebSocket::sendOneFrameTextAsync
Send one frame text message.
- @param message - message text. oatpp::String.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter sendOneFrameTextAsync(const oatpp::String& message)
# AsyncWebSocket::sendOneFrameBinaryAsync
Send one frame binary message.
- @param message - message text. oatpp::String.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter sendOneFrameBinaryAsync(const oatpp::String& message)
# AsyncWebSocket::Listener
Listener for websocket events.
namespace oatpp { namespace websocket {
class AsyncWebSocket : public oatpp::base::Countable, public std::enable_shared_from_this<AsyncWebSocket> {
class Listener {}
};
}}
# Typedefs
Type | Name | Summary |
---|---|---|
oatpp::async::Action | Action | Convenience typedef for oatpp::async::Action. |
oatpp::async::CoroutineStarter | CoroutineStarter | Convenince typedef for oatpp::async::CoroutineStarter. |
oatpp::websocket::AsyncWebSocket | AsyncWebSocket | Convenience typedef for oatpp::websocket::AsyncWebSocket. |
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | ~Listener | Default virtual destructor. |
CoroutineStarter | onPing | Called when "ping" frame received |
CoroutineStarter | onPong | Called when "pong" frame received |
CoroutineStarter | onClose | Called when "close" frame received |
CoroutineStarter | readMessage | Called when "text" or "binary" frame received. |
# AsyncWebSocket::Listener::Action
Convenience typedef for oatpp::async::Action.
typedef oatpp::async::Action Action
# AsyncWebSocket::Listener::CoroutineStarter
Convenince typedef for oatpp::async::CoroutineStarter.
typedef oatpp::async::CoroutineStarter CoroutineStarter
# AsyncWebSocket::Listener::AsyncWebSocket
Convenience typedef for oatpp::websocket::AsyncWebSocket.
typedef oatpp::websocket::AsyncWebSocket AsyncWebSocket
# AsyncWebSocket::Listener::~Listener
Default virtual destructor.
virtual ~Listener() = default
# AsyncWebSocket::Listener::onPing
Called when "ping" frame received
- @param socket - oatpp::websocket::AsyncWebSocket.
- @param message - message received with the frame.
- @return - oatpp::async::CoroutineStarter. To ignore this event return nullptr.
virtual CoroutineStarter onPing(const std::shared_ptr<AsyncWebSocket>& socket, const oatpp::String& message) = 0
# AsyncWebSocket::Listener::onPong
Called when "pong" frame received
- @param socket - oatpp::websocket::AsyncWebSocket.
- @param message - message received with the frame.
- @return - oatpp::async::CoroutineStarter.
To ignore this event return nullptr.
virtual CoroutineStarter onPong(const std::shared_ptr<AsyncWebSocket>& socket, const oatpp::String& message) = 0
# AsyncWebSocket::Listener::onClose
Called when "close" frame received
- @param socket - oatpp::websocket::AsyncWebSocket.
- @param code - code of the websocket connection close message.
- @param message - message text. oatpp::String.
- @return - oatpp::async::CoroutineStarter.
To ignore this event return nullptr.
virtual CoroutineStarter onClose(const std::shared_ptr<AsyncWebSocket>& socket, v_uint16 code, const oatpp::String& message) = 0
# AsyncWebSocket::Listener::readMessage
Called when "text" or "binary" frame received.
When all data of message is read, readMessage is called again with size == 0 to indicate end of the message.
- @param socket - oatpp::websocket::AsyncWebSocket.
- @param opcode - oatpp::websocket::Frame::OPCODE_TEXT or oatpp::websocket::Frame::OPCODE_BINARY.
- @param data - pointer to received data.
- @param size - data size. oatpp::v_io_size.
- @return - oatpp::async::CoroutineStarter.
To ignore this event return nullptr.
virtual CoroutineStarter readMessage(const std::shared_ptr<AsyncWebSocket>& socket, v_uint8 opcode, p_char8 data, oatpp::v_io_size size) = 0