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:
  1. Constructor.
  2. Deleted copy-constructor.
std::shared_ptr<AsyncWebSocket> createShared Create shared AsyncWebSocket.
std::shared_ptr<oatpp::data::stream::IOStream> getConnection Get socket connection.
void setListener Set 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:
  1. Send close frame.
  2. Send close frame without message.
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

  1. Constructor.
    AsyncWebSocket(const std::shared_ptr<oatpp::data::stream::IOStream>& connection, bool maskOutgoingMessages)
    
  2. Deleted copy-constructor.
    AsyncWebSocket(const AsyncWebSocket&) = delete
    

AsyncWebSocket::createShared

Create shared AsyncWebSocket.

  • @param connection - oatpp::data::stream::IOStream.
  • @param maskOutgoingMessages - for servers should be false. For clients should be true.
  • @return - std::shared_ptr to AsyncWebSocket.

static std::shared_ptr<AsyncWebSocket> createShared(const std::shared_ptr<oatpp::data::stream::IOStream>& connection, bool maskOutgoingMessages)

AsyncWebSocket::getConnection

Get socket connection.

std::shared_ptr<oatpp::data::stream::IOStream> getConnection() const

AsyncWebSocket::setListener

Set socket event listener.

void setListener(const std::shared_ptr<Listener>& listener)

AsyncWebSocket::listenAsync

Start listening Coroutine.
Read incoming frames and call corresponding methods of listener. See AsyncWebSocket::setListener().

CoroutineStarter listenAsync()

AsyncWebSocket::writeFrameHeaderAsync

Send custom frame to peer.
Use this method if you know what you are doing.

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.

CoroutineStarter sendFrameHeaderAsync(const std::shared_ptr<Frame::Header>& frameHeader, bool fin, v_word8 opcode, v_int64 messageSize)

AsyncWebSocket::sendOneFrameAsync

Send one frame message with custom fin and opcode.

CoroutineStarter sendOneFrameAsync(bool fin, v_word8 opcode, const oatpp::String& message)

AsyncWebSocket::sendCloseAsync

  1. Send close frame.
    CoroutineStarter sendCloseAsync(v_word16 code, const oatpp::String& message)
    
  2. Send close frame without message.
    CoroutineStarter sendCloseAsync()
    

AsyncWebSocket::sendPingAsync

Send ping frame.

CoroutineStarter sendPingAsync(const oatpp::String& message)

AsyncWebSocket::sendPongAsync

Send pong frame.

CoroutineStarter sendPongAsync(const oatpp::String& message)

AsyncWebSocket::sendOneFrameTextAsync

Send one frame text message.

CoroutineStarter sendOneFrameTextAsync(const oatpp::String& message)

AsyncWebSocket::sendOneFrameBinaryAsync

Send one frame binary message.

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
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::onPing

Called when "ping" frame received

virtual CoroutineStarter onPing(const std::shared_ptr<AsyncWebSocket>& socket, const oatpp::String& message) = 0

AsyncWebSocket::Listener::onPong

Called when "pong" frame received

virtual CoroutineStarter onPong(const std::shared_ptr<AsyncWebSocket>& socket, const oatpp::String& message) = 0

AsyncWebSocket::Listener::onClose

Called when "close" frame received

virtual CoroutineStarter onClose(const std::shared_ptr<AsyncWebSocket>& socket, v_word16 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.

virtual CoroutineStarter readMessage(const std::shared_ptr<AsyncWebSocket>& socket, p_char8 data, data::v_io_size size) = 0