NDEVR
API Documentation
TcpServer

A TcpServer allows the software to receive socket connections from external sources. More...

Collaboration diagram for TcpServer:
[legend]

Public Member Functions

 TcpServer (const String &server_name, QObject *parent=0)
 Constructs a TcpServer without binding to a port (client-only or deferred listen).
 TcpServer (const String &server_name, uint04 port, QObject *parent=0)
 Constructs a TcpServer that listens on the specified port.
void connectToRemoteServer (const String &remote_address)
 Connects to a remote TcpServer at the given address string.
void connectToRemoteServer (QTcpSocket *remote_socket)
 Connects to a remote TcpServer using an existing QTcpSocket.
void discardSocketSlot ()
 Slot invoked when a socket is disconnected and should be discarded.
void displayErrorSlot (int socketError)
 Slot invoked when a socket error occurs.
void newConnectionSlot ()
 Slot invoked when a new incoming TCP connection is established.
void readSocketSlot ()
 Slot invoked when data is available to read from a connected socket.
virtual bool sendData (const StringView &data, QTcpSocket *socket=nullptr)
 Sends a generic data string to the specified socket or all connected sockets.
virtual bool sendData (const StringView &data_type, const StringView &data, QTcpSocket *socket=nullptr)
 Sends a typed data message to the specified socket or all connected sockets.
virtual bool sendError (const Exception &e, QTcpSocket *socket=nullptr)
 Sends an error message to the specified socket or all connected sockets.
virtual bool sendFile (const File &file, bool send_file_contents, QTcpSocket *socket=nullptr)
 Sends a file with control over whether contents are included.
virtual bool sendFile (const File &file, QTcpSocket *socket=nullptr)
 Sends a file (metadata and contents) to the specified socket or all connected sockets.
virtual bool sendOpenApp (const File &application, const String &args, bool wait_for_completion, bool windowless, QTcpSocket *socket=nullptr)
 Sends a command to launch an application on the remote end.
virtual bool sendPacket (const QByteArray &packet, QTcpSocket *socket=nullptr)
 Sends a raw pre-built packet to the specified socket or all connected sockets.
virtual bool sendSetScreenResolution (const Vector< 2, uint04 > &size, QTcpSocket *socket=nullptr)
 Sends a command to set the screen resolution on the remote end.
virtual bool sendShowFileBrowser (QTcpSocket *socket=nullptr)
 Sends a command to show a file browser on the remote end.

Static Public Member Functions

static QByteArray CreateFilePacket (const File &file, bool send_file_contents)
 Creates a file transfer packet.
static QByteArray CreateMessagePacket (const StringView &type, const StringView &data, const StringView &args=StringView())
 Creates a message packet with the given type, data, and optional arguments.
static QByteArray CreateOpenAppPacket (const File &application, const String &args=String(), bool wait_for_completion=true, bool windowless=false)
 Creates a packet instructing the remote end to launch an application.
static QByteArray CreateOpenFilePacket (const File &file_to_open)
 Creates a packet instructing the remote end to open a file in its default handler.
static QByteArray CreateRequestSendFilePacket (const File &file_to_request, const String &args=String())
 Creates a packet requesting the remote end to send a specific file back.
static QByteArray CreateSendErrorPacket (const Exception &e)
 Creates a packet containing an error message to send to the remote end.

Static Public Attributes

static constexpr StringView error_data_message = "send_error_message"
 Message type for error messages.
static constexpr StringView generic_data_message_type = "data"
 Message type for generic data payloads.
static constexpr StringView generic_file_message_type = "file"
 Message type for generic file transfers.
static constexpr StringView open_file_message_type = "open_file"
 Message type to open a file remotely.
static constexpr StringView open_os_settings = "open_os_settings"
 Message type to open OS settings on the remote end.
static constexpr StringView request_send_file = "request_send_file"
 Message type to request a file from the remote end.
static constexpr StringView set_screen_resolution = "set_screen_resolution"
 Message type to set screen resolution remotely.
static constexpr StringView start_application_file_message_type = "start_application"
 Message type to start an application remotely.

Protected Member Functions

virtual bool dataReceived (const String &data_type, const String &args, const String &data, QTcpSocket *socket)
 Called when a data message is received from a connected socket.
virtual bool fileReceived (const String &data_type, const String &args, const File &data, QTcpSocket *socket)
 Called when a file message is received from a connected socket.
virtual void showError (const Exception &e)
 Displays or logs an error from an exception; override for custom error handling.
virtual void socketDisconnected (QTcpSocket *socket)
 Called when a socket has been disconnected; override to handle cleanup.

Detailed Description

A TcpServer allows the software to receive socket connections from external sources.


Provides a message-based protocol over TCP for sending and receiving data, files, and commands between networked applications.

Note
Typos in method names: dataReceived, fileReceived, and CreateRequestSendFilePacket are misspelled in the interface but preserved for binary compatibility.

Definition at line 22 of file TcpServer.h.

Constructor & Destructor Documentation

◆ TcpServer() [1/2]

TcpServer::TcpServer ( const String & server_name,
uint04 port,
QObject * parent = 0 )
explicit

Constructs a TcpServer that listens on the specified port.

Parameters
[in]server_nameA human-readable name for this server instance.
[in]portThe TCP port number to listen on.
[in]parentThe parent QObject.

◆ TcpServer() [2/2]

TcpServer::TcpServer ( const String & server_name,
QObject * parent = 0 )
explicit

Constructs a TcpServer without binding to a port (client-only or deferred listen).

Parameters
[in]server_nameA human-readable name for this server instance.
[in]parentThe parent QObject.

Member Function Documentation

◆ connectToRemoteServer() [1/2]

void TcpServer::connectToRemoteServer ( const String & remote_address)

Connects to a remote TcpServer at the given address string.

Parameters
[in]remote_addressThe address of the remote server (e.g., "192.168.1.1:5000").

◆ connectToRemoteServer() [2/2]

void TcpServer::connectToRemoteServer ( QTcpSocket * remote_socket)

Connects to a remote TcpServer using an existing QTcpSocket.

Parameters
[in]remote_socketThe pre-connected TCP socket to use.

◆ CreateFilePacket()

QByteArray TcpServer::CreateFilePacket ( const File & file,
bool send_file_contents )
static

Creates a file transfer packet.

Parameters
[in]fileThe file to include in the packet.
[in]send_file_contentsWhether to embed the file contents or just the metadata.
Returns
The serialized packet as a QByteArray.

◆ CreateMessagePacket()

QByteArray TcpServer::CreateMessagePacket ( const StringView & type,
const StringView & data,
const StringView & args = StringView() )
static

Creates a message packet with the given type, data, and optional arguments.

Parameters
[in]typeThe message type identifier.
[in]dataThe message payload.
[in]argsOptional arguments for the message.
Returns
The serialized packet as a QByteArray.

◆ CreateOpenAppPacket()

QByteArray TcpServer::CreateOpenAppPacket ( const File & application,
const String & args = String(),
bool wait_for_completion = true,
bool windowless = false )
static

Creates a packet instructing the remote end to launch an application.

Parameters
[in]applicationThe application executable file.
[in]argsCommand-line arguments for the application.
[in]wait_for_completionWhether the remote should wait for the application to exit.
[in]windowlessWhether to launch the application without a visible window.
Returns
The serialized packet as a QByteArray.

◆ CreateOpenFilePacket()

QByteArray TcpServer::CreateOpenFilePacket ( const File & file_to_open)
static

Creates a packet instructing the remote end to open a file in its default handler.

Parameters
[in]file_to_openThe file to open.
Returns
The serialized packet as a QByteArray.

◆ CreateRequestSendFilePacket()

QByteArray TcpServer::CreateRequestSendFilePacket ( const File & file_to_request,
const String & args = String() )
static

Creates a packet requesting the remote end to send a specific file back.

Parameters
[in]file_to_requestThe file being requested.
[in]argsOptional arguments for the request.
Returns
The serialized packet as a QByteArray.

◆ CreateSendErrorPacket()

QByteArray TcpServer::CreateSendErrorPacket ( const Exception & e)
static

Creates a packet containing an error message to send to the remote end.

Parameters
[in]eThe exception to serialize.
Returns
The serialized packet as a QByteArray.

◆ dataReceived()

virtual bool TcpServer::dataReceived ( const String & data_type,
const String & args,
const String & data,
QTcpSocket * socket )
protectedvirtual

Called when a data message is received from a connected socket.

Parameters
[in]data_typeThe message type identifier.
[in]argsAdditional arguments accompanying the message.
[in]dataThe message payload.
[in]socketThe socket that sent the data.
Returns
True if the data was handled successfully, false otherwise.

◆ displayErrorSlot()

void TcpServer::displayErrorSlot ( int socketError)

Slot invoked when a socket error occurs.

Parameters
[in]socketErrorThe socket error code.

◆ fileReceived()

virtual bool TcpServer::fileReceived ( const String & data_type,
const String & args,
const File & data,
QTcpSocket * socket )
protectedvirtual

Called when a file message is received from a connected socket.

Parameters
[in]data_typeThe message type identifier.
[in]argsAdditional arguments accompanying the message.
[in]dataThe received file.
[in]socketThe socket that sent the file.
Returns
True if the file was handled successfully, false otherwise.

◆ sendData() [1/2]

virtual bool TcpServer::sendData ( const StringView & data,
QTcpSocket * socket = nullptr )
virtual

Sends a generic data string to the specified socket or all connected sockets.

Parameters
[in]dataThe data string to send.
[in]socketThe target socket, or nullptr to broadcast to all.
Returns
True if the data was sent successfully, false otherwise.

◆ sendData() [2/2]

virtual bool TcpServer::sendData ( const StringView & data_type,
const StringView & data,
QTcpSocket * socket = nullptr )
virtual

Sends a typed data message to the specified socket or all connected sockets.

Parameters
[in]data_typeThe message type identifier.
[in]dataThe message payload.
[in]socketThe target socket, or nullptr to broadcast to all.
Returns
True if the data was sent successfully, false otherwise.

◆ sendError()

virtual bool TcpServer::sendError ( const Exception & e,
QTcpSocket * socket = nullptr )
virtual

Sends an error message to the specified socket or all connected sockets.

Parameters
[in]eThe exception to send.
[in]socketThe target socket, or nullptr to broadcast to all.
Returns
True if the error was sent successfully, false otherwise.

◆ sendFile() [1/2]

virtual bool TcpServer::sendFile ( const File & file,
bool send_file_contents,
QTcpSocket * socket = nullptr )
virtual

Sends a file with control over whether contents are included.

Parameters
[in]fileThe file to send.
[in]send_file_contentsWhether to embed the file contents or just metadata.
[in]socketThe target socket, or nullptr to broadcast to all.
Returns
True if the file was sent successfully, false otherwise.

◆ sendFile() [2/2]

virtual bool TcpServer::sendFile ( const File & file,
QTcpSocket * socket = nullptr )
virtual

Sends a file (metadata and contents) to the specified socket or all connected sockets.

Parameters
[in]fileThe file to send.
[in]socketThe target socket, or nullptr to broadcast to all.
Returns
True if the file was sent successfully, false otherwise.

◆ sendOpenApp()

virtual bool TcpServer::sendOpenApp ( const File & application,
const String & args,
bool wait_for_completion,
bool windowless,
QTcpSocket * socket = nullptr )
virtual

Sends a command to launch an application on the remote end.

Parameters
[in]applicationThe application executable file.
[in]argsCommand-line arguments.
[in]wait_for_completionWhether the remote should wait for the application to exit.
[in]windowlessWhether to launch without a visible window.
[in]socketThe target socket, or nullptr to broadcast to all.
Returns
True if the command was sent successfully, false otherwise.

◆ sendPacket()

virtual bool TcpServer::sendPacket ( const QByteArray & packet,
QTcpSocket * socket = nullptr )
virtual

Sends a raw pre-built packet to the specified socket or all connected sockets.

Parameters
[in]packetThe serialized packet data to send.
[in]socketThe target socket, or nullptr to broadcast to all.
Returns
True if the packet was sent successfully, false otherwise.

◆ sendSetScreenResolution()

virtual bool TcpServer::sendSetScreenResolution ( const Vector< 2, uint04 > & size,
QTcpSocket * socket = nullptr )
virtual

Sends a command to set the screen resolution on the remote end.

Parameters
[in]sizeThe desired screen resolution as a 2D vector (width, height).
[in]socketThe target socket, or nullptr to broadcast to all.
Returns
True if the command was sent successfully, false otherwise.

◆ sendShowFileBrowser()

virtual bool TcpServer::sendShowFileBrowser ( QTcpSocket * socket = nullptr)
virtual

Sends a command to show a file browser on the remote end.

Parameters
[in]socketThe target socket, or nullptr to broadcast to all.
Returns
True if the command was sent successfully, false otherwise.

◆ showError()

virtual void TcpServer::showError ( const Exception & e)
protectedvirtual

Displays or logs an error from an exception; override for custom error handling.

Parameters
[in]eThe exception to display.

◆ socketDisconnected()

virtual void TcpServer::socketDisconnected ( QTcpSocket * socket)
protectedvirtual

Called when a socket has been disconnected; override to handle cleanup.

Parameters
[in]socketThe socket that was disconnected.

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