![]() |
NDEVR
API Documentation
|
A TcpServer allows the software to receive socket connections from external sources. More...
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. | |
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.
Definition at line 22 of file TcpServer.h.
Constructs a TcpServer that listens on the specified port.
| [in] | server_name | A human-readable name for this server instance. |
| [in] | port | The TCP port number to listen on. |
| [in] | parent | The parent QObject. |
|
explicit |
Constructs a TcpServer without binding to a port (client-only or deferred listen).
| [in] | server_name | A human-readable name for this server instance. |
| [in] | parent | The parent QObject. |
| void TcpServer::connectToRemoteServer | ( | const String & | remote_address | ) |
Connects to a remote TcpServer at the given address string.
| [in] | remote_address | The address of the remote server (e.g., "192.168.1.1:5000"). |
| void TcpServer::connectToRemoteServer | ( | QTcpSocket * | remote_socket | ) |
Connects to a remote TcpServer using an existing QTcpSocket.
| [in] | remote_socket | The pre-connected TCP socket to use. |
|
static |
Creates a file transfer packet.
| [in] | file | The file to include in the packet. |
| [in] | send_file_contents | Whether to embed the file contents or just the metadata. |
|
static |
Creates a message packet with the given type, data, and optional arguments.
| [in] | type | The message type identifier. |
| [in] | data | The message payload. |
| [in] | args | Optional arguments for the message. |
|
static |
Creates a packet instructing the remote end to launch an application.
| [in] | application | The application executable file. |
| [in] | args | Command-line arguments for the application. |
| [in] | wait_for_completion | Whether the remote should wait for the application to exit. |
| [in] | windowless | Whether to launch the application without a visible window. |
|
static |
Creates a packet instructing the remote end to open a file in its default handler.
| [in] | file_to_open | The file to open. |
|
static |
Creates a packet requesting the remote end to send a specific file back.
| [in] | file_to_request | The file being requested. |
| [in] | args | Optional arguments for the request. |
|
static |
Creates a packet containing an error message to send to the remote end.
| [in] | e | The exception to serialize. |
|
protectedvirtual |
Called when a data message is received from a connected socket.
| [in] | data_type | The message type identifier. |
| [in] | args | Additional arguments accompanying the message. |
| [in] | data | The message payload. |
| [in] | socket | The socket that sent the data. |
| void TcpServer::displayErrorSlot | ( | int | socketError | ) |
Slot invoked when a socket error occurs.
| [in] | socketError | The socket error code. |
|
protectedvirtual |
Called when a file message is received from a connected socket.
| [in] | data_type | The message type identifier. |
| [in] | args | Additional arguments accompanying the message. |
| [in] | data | The received file. |
| [in] | socket | The socket that sent the file. |
|
virtual |
Sends a generic data string to the specified socket or all connected sockets.
| [in] | data | The data string to send. |
| [in] | socket | The target socket, or nullptr to broadcast to all. |
|
virtual |
Sends a typed data message to the specified socket or all connected sockets.
| [in] | data_type | The message type identifier. |
| [in] | data | The message payload. |
| [in] | socket | The target socket, or nullptr to broadcast to all. |
|
virtual |
Sends an error message to the specified socket or all connected sockets.
| [in] | e | The exception to send. |
| [in] | socket | The target socket, or nullptr to broadcast to all. |
|
virtual |
Sends a file with control over whether contents are included.
| [in] | file | The file to send. |
| [in] | send_file_contents | Whether to embed the file contents or just metadata. |
| [in] | socket | The target socket, or nullptr to broadcast to all. |
|
virtual |
Sends a file (metadata and contents) to the specified socket or all connected sockets.
| [in] | file | The file to send. |
| [in] | socket | The target socket, or nullptr to broadcast to all. |
|
virtual |
Sends a command to launch an application on the remote end.
| [in] | application | The application executable file. |
| [in] | args | Command-line arguments. |
| [in] | wait_for_completion | Whether the remote should wait for the application to exit. |
| [in] | windowless | Whether to launch without a visible window. |
| [in] | socket | The target socket, or nullptr to broadcast to all. |
|
virtual |
Sends a raw pre-built packet to the specified socket or all connected sockets.
| [in] | packet | The serialized packet data to send. |
| [in] | socket | The target socket, or nullptr to broadcast to all. |
|
virtual |
Sends a command to set the screen resolution on the remote end.
| [in] | size | The desired screen resolution as a 2D vector (width, height). |
| [in] | socket | The target socket, or nullptr to broadcast to all. |
|
virtual |
Sends a command to show a file browser on the remote end.
| [in] | socket | The target socket, or nullptr to broadcast to all. |
|
protectedvirtual |
Displays or logs an error from an exception; override for custom error handling.
| [in] | e | The exception to display. |
|
protectedvirtual |
Called when a socket has been disconnected; override to handle cleanup.
| [in] | socket | The socket that was disconnected. |