trikRuntime
trikNetwork::TrikServer Class Reference

Server that can handle multiple clients. Actual work is done in separate threads by Connection objects. More...

#include <trikServer.h>

Inheritance diagram for trikNetwork::TrikServer:
Collaboration diagram for trikNetwork::TrikServer:

Public Slots

void sendMessage (const QString &message)
 Broadcasts message across all opened connections. More...
 

Signals

void connected ()
 Emitted when we get the first connection established. More...
 
void disconnected ()
 Emitted when the last connection closes. More...
 

Public Member Functions

 TrikServer (const std::function< Connection *()> &connectionFactory)
 Constructor. More...
 
 ~TrikServer () override
 
int activeConnections () const
 Returns number of connections currently opened. More...
 
Q_INVOKABLE void startServer (quint16 port)
 Starts listening given port on all network interfaces. More...
 

Protected Member Functions

void incomingConnection (qintptr socketDescriptor) override
 
void startConnection (Connection *connectionWorker)
 Launches given connection in a separate thread. Takes ownership over connectionWorker object. More...
 
Connectionconnection (const QHostAddress &ip, int port) const
 Searches connection to given IP and port in a list of all open connections. More...
 
Connectionconnection (const QHostAddress &ip) const
 Searches connection to given IP and any port in a list of all open connections. More...
 

Detailed Description

Server that can handle multiple clients. Actual work is done in separate threads by Connection objects.

Constructor & Destructor Documentation

TrikServer::TrikServer ( const std::function< Connection *()> &  connectionFactory)
explicit

Constructor.

Parameters
connectionFactory- function that provides actual connection objects.
TrikServer::~TrikServer ( )
override

Member Function Documentation

int TrikServer::activeConnections ( ) const

Returns number of connections currently opened.

void trikNetwork::TrikServer::connected ( )
signal

Emitted when we get the first connection established.

Connection * TrikServer::connection ( const QHostAddress &  ip,
int  port 
) const
protected

Searches connection to given IP and port in a list of all open connections.

Note that if connection is added by startConnection() call but not finished to open yet, it will not be found.

Connection * TrikServer::connection ( const QHostAddress &  ip) const
protected

Searches connection to given IP and any port in a list of all open connections.

Will return arbitrary matching connection if there are more than one connection with this IP. Note that if connection is added by startConnection() call but not finished to open yet, it will not be found.

void trikNetwork::TrikServer::disconnected ( )
signal

Emitted when the last connection closes.

void TrikServer::incomingConnection ( qintptr  socketDescriptor)
overrideprotected
void TrikServer::sendMessage ( const QString &  message)
slot

Broadcasts message across all opened connections.

void TrikServer::startConnection ( Connection connectionWorker)
protected

Launches given connection in a separate thread. Takes ownership over connectionWorker object.

Todo:
: Emit "connected" signal only when socket is actually connected.
void TrikServer::startServer ( quint16  port)

Starts listening given port on all network interfaces.


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