ofxHTTP
A collection of tools for HTTP.
ofx::HTTP::WebSocketConnection Class Reference

A class representing a WebSocket connection with a single client. More...

#include <WebSocketConnection.h>

Inheritance diagram for ofx::HTTP::WebSocketConnection:
ofx::HTTP::BaseRouteHandler_< WebSocketRoute > ofx::HTTP::AbstractRouteHandler ofx::HTTP::AbstractHTTPRequestHandler ofx::HTTP::AbstractServerEventRequestHandler

Public Member Functions

 WebSocketConnection (WebSocketRoute &route)
 Create a WebSocketConnection. More...
 
virtual ~WebSocketConnection ()
 Destroy the WebSocketConnection.
 
void handleRequest (ServerEventArgs &evt) override
 Handle the ServerEventArgs. More...
 
bool sendFrame (const WebSocketFrame &frame) const
 Queue a frame to be sent. More...
 
void stop () override
 Interrupt the handleRequest method if possible.
 
Poco::Net::NameValueCollection requestHeaders () const
 
Poco::Net::SocketAddress clientAddress () const
 
bool isConnected () const
 
std::size_t sendQueueSize () const
 
void clearSendQueue ()
 Clears the send queue.
 
std::size_t totalBytesSent () const
 Get the total bytes sent to the client. More...
 
std::size_t totalBytesReceived () const
 Get the total bytes received from the client. More...
 
void addWebSocketFilter (std::unique_ptr< AbstractWebSocketFilter > filter)
 Take ownership of the passed std::unique_ptr<ExtensionType>. More...
 
- Public Member Functions inherited from ofx::HTTP::BaseRouteHandler_< WebSocketRoute >
 BaseRouteHandler_ (WebSocketRoute &route)
 Create a BaseRoute.
 
virtual ~BaseRouteHandler_ ()
 Destroy a BaseRoute.
 
void handleRequest (Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response) override
 
WebSocketRouteroute ()
 Get the dispatching route.
 
- Public Member Functions inherited from ofx::HTTP::AbstractRouteHandler
virtual ~AbstractRouteHandler ()
 Destroy the AbstractRouteHandler instance.
 
- Public Member Functions inherited from ofx::HTTP::AbstractHTTPRequestHandler
virtual ~AbstractHTTPRequestHandler ()
 Destroy the AbstractHTTPRequestHandler.
 
- Public Member Functions inherited from ofx::HTTP::AbstractServerEventRequestHandler
virtual ~AbstractServerEventRequestHandler ()
 Destroy the AbstractServerEventRequestHandler.
 

Additional Inherited Members

- Protected Attributes inherited from ofx::HTTP::BaseRouteHandler_< WebSocketRoute >
WebSocketRoute_route
 The route.
 

Detailed Description

A class representing a WebSocket connection with a single client.

Frames can be sent across thread boundaries and are queued for sending during the WebSocketConnection's service loop. All accessors are synchronized and thread-safe.

Constructor & Destructor Documentation

◆ WebSocketConnection()

ofx::HTTP::WebSocketConnection::WebSocketConnection ( WebSocketRoute route)

Create a WebSocketConnection.

Parameters
routeA reference to the parent WebSocketRoute.

Member Function Documentation

◆ addWebSocketFilter()

void ofx::HTTP::WebSocketConnection::addWebSocketFilter ( std::unique_ptr< AbstractWebSocketFilter filter)

Take ownership of the passed std::unique_ptr<ExtensionType>.

Parameters
filterthe rvalue reference to the filter.

◆ clientAddress()

Poco::Net::SocketAddress ofx::HTTP::WebSocketConnection::clientAddress ( ) const
Returns
the client's SocketAddress.

◆ handleRequest()

void ofx::HTTP::WebSocketConnection::handleRequest ( ServerEventArgs evt)
overridevirtual

Handle the ServerEventArgs.

Parameters
evtThe server request event.
Todo:
Fix when poco is upgraded.

Implements ofx::HTTP::BaseRouteHandler_< WebSocketRoute >.

◆ isConnected()

bool ofx::HTTP::WebSocketConnection::isConnected ( ) const
Returns
true iff this WebSocketConnect is connected to a client.

◆ requestHeaders()

Poco::Net::NameValueCollection ofx::HTTP::WebSocketConnection::requestHeaders ( ) const
Returns
The original http request headers.

◆ sendFrame()

bool ofx::HTTP::WebSocketConnection::sendFrame ( const WebSocketFrame frame) const

Queue a frame to be sent.

Returns
false iff frame not queued

◆ sendQueueSize()

std::size_t ofx::HTTP::WebSocketConnection::sendQueueSize ( ) const
Returns
the size of the send queue.

◆ totalBytesReceived()

std::size_t ofx::HTTP::WebSocketConnection::totalBytesReceived ( ) const

Get the total bytes received from the client.

Returns
the total bytes received from the client.

◆ totalBytesSent()

std::size_t ofx::HTTP::WebSocketConnection::totalBytesSent ( ) const

Get the total bytes sent to the client.

Returns
the total bytes sent to the client.

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