NDEVR
API Documentation
AdaptiveTCPClient.h
1#pragma once
2#include <NDEVR/NDEVRCommunicationLogic.h>
3#include <NDEVR/String.h>
4#include <NDEVR/QueueBuffer.h>
5#include <QWebSocket>
6#include <QTcpSocket>
7#include <QTimer>
8namespace NDEVR
9{
15 class AdaptiveTCPClient : public QObject, public NDEVRCommunicationLogic
16 {
17 Q_OBJECT
18 public:
22 explicit AdaptiveTCPClient(QObject* parent = nullptr);
27 void connectToServer(const StringView& host, uint04 port);
33 virtual uint08 rx(void* socket, NDEVRDataPacket& packet) override;
40 virtual uint08 tx(void* socket, NDEVRDataPacket& packet, uint08 size) override;
45 virtual void wait(const TimeSpan& span, LogPtr log = nullptr) override;
50 void* connectTo(const NDEVRServerInfo& server) override;
54 virtual void disconnectFrom(void* socket) override;
59 virtual bool isOpen(void* socket = nullptr) const override;
60 private slots:
62 void onConnected();
64 void onReadyRead();
68 void onBytesWritten(qint64);
70 void onSendTick();
72 void onReconnectTimeout();
73 protected:
75 QTimer m_send_timer;
76 QTcpSocket* m_server_socket;
77 };
78}
QTimer reconnectTimer
Timer for automatic reconnection attempts.
QTimer m_send_timer
Timer for periodic send buffer flushing.
virtual void disconnectFrom(void *socket) override
Disconnects from the specified socket.
virtual void wait(const TimeSpan &span, LogPtr log=nullptr) override
Waits for the specified time span, processing events.
AdaptiveTCPClient(QObject *parent=nullptr)
Constructs the TCP client.
void connectToServer(const StringView &host, uint04 port)
Initiates a TCP connection to the specified host and port.
virtual bool isOpen(void *socket=nullptr) const override
Checks whether the socket is currently connected.
virtual uint08 rx(void *socket, NDEVRDataPacket &packet) override
Receives data from the socket into a packet.
QTcpSocket * m_server_socket
The underlying TCP socket.
virtual uint08 tx(void *socket, NDEVRDataPacket &packet, uint08 size) override
Transmits packet data through the socket.
void * connectTo(const NDEVRServerInfo &server) override
Establishes a connection to the specified server.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
The core String View class for the NDEVR API.
Definition StringView.h:58
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
The primary namespace for the NDEVR SDK.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Contains the address, credentials, and security flag needed to connect to an NDEVR server.