Loading...
Searching...
No Matches
ServerSentEventHandler::ServerSentEventConnection Class Reference

this class represents a connection to an HTTP client More...

`#include <ServerSentEventConnection.qc.dox.h>`

## Public Member Functions

| connectionClosed ()
| This method is called when the connection is closed.
| constructor (ServerSentEventHandler handler, Socket sock, hash< auto > cx, hash< auto > hdr, string cid)
| the constructor is called when a new connection is made by an HTTP client
| flush ()
| Flush all output data.
*string | pollData ()
| This method is called to poll for messages from the client to send from the server.
*string | pollDataImmediate ()
| This method is called to poll for messages to send to the client from the server.
| registered ()
| Called when the connection has been registered in handler and accept sending messages.
| send (hash< SseMessageInfo > msg)
| Pushes an unencoded message on the connection's message queue.
| sendEncoded (string msg)
| Pushes an already-encoded message on the connection's message queue.
| stop ()
| force closing socket related to connection

## Public Attributes

string | cid
| The connection ID.
hash< auto > | cx
| Original request context.
ServerSentEventHandler | handler
| The parent handler object.
hash< auto > | hdr
| Original request header info.
bool | stop_flag = False
| Stop connection flag.

## Protected Member Functions

Qore::Thread::Queue | queue ()
| the Queue object stores messages to be sent to the server

## Protected Attributes

int | tid = gettid()
| The TID of the I/O thread.

## Private Attributes

Socket | sock
| The socket used by the server for this connection.

## Detailed Description

this class represents a connection to an HTTP client

Sending ServerSentEvent Message to Clients
  To send a message to an HTTP client, call one of the following methods:
  - ServerSentEventConnection::send(): to send an unencoded message to the client
  - ServerSentEventConnection::sendEncoded(): to send an already-encoded message to the client

Note
  Reference: https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream

## Member Function Documentation

## connectionClosed()

ServerSentEventHandler::ServerSentEventConnection::connectionClosed | ( |  | ) |

This method is called when the connection is closed.

Called by the ServerSentEventHandler

The implementation in this class is empty; implement this method in a subclass to provide custom behavior

## constructor()

ServerSentEventHandler::ServerSentEventConnection::constructor | ( | ServerSentEventHandler | handler,
|  | Socket | sock,
|  | hash< auto > | cx,
|  | hash< auto > | hdr,
|  | string | cid )

the constructor is called when a new connection is made by an HTTP client

Called from ServerSentEventHandler::getConnectionImpl(), which can be overridden in subclasses to allow a subclass of this class to be used as the connection object

## pollData()

*string ServerSentEventHandler::ServerSentEventConnection::pollData | ( |  | ) |

This method is called to poll for messages from the client to send from the server.

Called by the ServerSentEventHandler

## pollDataImmediate()

*string ServerSentEventHandler::ServerSentEventConnection::pollDataImmediate | ( |  | ) |

This method is called to poll for messages to send to the client from the server.

Called by the ServerSentEventHandler

## registered()

ServerSentEventHandler::ServerSentEventConnection::registered | ( |  | ) |

Called when the connection has been registered in handler and accept sending messages.

Can be used to send initial welcome message, for example; the default implementation does nothing

## send()

ServerSentEventHandler::ServerSentEventConnection::send | ( | hash< SseMessageInfo > | msg | ) |

Pushes an unencoded message on the connection's message queue.

The message will be encoded with ServerSentEventUtil::ws_encode_message() before sending