Knut Client¶
-
class
KnutClient
: public QObject¶ The client which connects to the Knut server.
The KnutClient can be used by all services to communicate to the Knut server or to get any messages from the server. Each service can therefore connect to the receivedMessage() signal to receive any incoming message or send requests using writeRequest().
Public Functions
-
void
setHostAddress
(const QString &hostAddress)¶ Changes the hostAddress to which the KnutClient is bound and reconnects to it.
-
void
setPort
(const int &port)¶ Changes the port of the socket connection and reconnects to the server.
-
void
writeRequest
(const QJsonObject &message, const quint8 &serviceId, const quint16 &messageId)¶ Writes a request to the socket with a message.
Write a request for the service serviceId and the JSON formatted message with it’s messageId identifier to the socket.
-
void
writeRequest
(const quint8 &serviceId, const quint16 &messageId)¶ Writes a request to the socket without message.
Write a request to the socket for the service serviceId and the messageId where the message is not required to have a JSON formatted message.
Public Slots
-
void
onDisconnected
()¶ Executed when the socket is disconnected.
Sets the connected property to false and starts a reconnection timer
-
void
onReadyRead
()¶ Reads a message from the socket.
Reads a null terminated Knut message from the socket as specified here. The JSON message must have the keys
"serviceid"
,"msgid"
and"msg"
. Those are read from the message and the signal receivedMessage() is emitted with the messsage, serviceId and messageId.As long as the socket has data available, data are read from the socket and for each message, the signal receivedMessage() is emitted.
Signals
-
void
receivedMessage
(const QJsonObject &message, const quint8 &serviceId, const quint16 &messageId)¶ Emitted when a new message is received.
This signal is emitted when a new message is received and processed. Any service can connect to it, check for the serviceId and process the message of type messageId if needed.
- Note
This signal should only be emitted when a valid Knut message is read from the socket by the onReadyRead() method.
- See
Property
-
property
KnutClient::connected
This property indicates whether the KnutClient is connected to the Knut server or not.
-
property
KnutClient::hostAddress
This property holds the address to which the Knut server is bound.
-
property
KnutClient::port
This property holds the port on which the Knut server can be accessed.
-
void