IpcClient Class

Client to send remote calls to an IpcServer More...

Header: #include <IpcClient>

Public Functions

IpcClient(QObject *parent = 0)
IpcClient(QTcpSocket *socket, QObject *parent = 0)
void connectToServer(const QString &hostName, int port)
QString errorToString(QAbstractSocket::SocketError error)
QUuid send(const QString &method, const QByteArray &data)
QAbstractSocket::SocketState state() const
bool waitForConnected(int msecs = 30000)
bool waitForDisconnected(int msecs = 30000)
bool waitForSent(const QUuid uuid, int msecs = 30000)

Public Slots

Signals

void connected()
void connectionError(QAbstractSocket::SocketError socketError)
void disconnected()
void received(const QString &method, const QByteArray &content)
void sendingError(const QUuid &uuid, QAbstractSocket::SocketError socketError)
void sentSuccessfully(const QUuid &uuid)

Detailed Description

Client to send remote calls to an IpcServer

The IPC system uses the normalized signal/slot signature to identify a message call. The arguments are passed as a QByteArray to the send function.

Here is a simple example:

IpcClient *client = new IpcClient(this);
client->connectToServer("127.0.0.1", 10234);
QString text = "Hello";
QByteArray content;
QDataStream out(&bytes, QIODevice::WriteOnly);
out << text;
QUuid uuid = client->send("echo(QString)", content);
client->waitForSent(uuid);

Don't use the waitFor*-Methods in your gui applications. They will block the eventloop. Instead react on the signals when the packages are sent or an error happened.

Member Function Documentation

IpcClient::IpcClient(QObject *parent = 0)

Constructs an IpcClient with parent parent to send commands to an IpcServer.

IpcClient::IpcClient(QTcpSocket *socket, QObject *parent = 0)

Default constructs an instance of IpcClient.

void IpcClient::connectToServer(const QString &hostName, int port)

Sets the Ip-Address to hostName and port to port to be used for a IPC call.

[signal] void IpcClient::connected()

Emitted once when the connection to the server is established

[signal] void IpcClient::connectionError(QAbstractSocket::SocketError socketError)

Emitted when an error happens when connecting or disconnecting from the server socketError describes what error happened

[slot] void IpcClient::disconnectFromServer()

Disconnects from the Server

[signal] void IpcClient::disconnected()

Emitted once when the connection to the server is terminated

QString IpcClient::errorToString(QAbstractSocket::SocketError error)

Converts the socket error error to a printable string

[signal] void IpcClient::received(const QString &method, const QByteArray &content)

Called when a RPC call was received. Provides the method and content

QUuid IpcClient::send(const QString &method, const QByteArray &data)

Send call to server given by destination

Expects the method to be in the form of "echo(QString)" and uses data as the content of the arguments Returns a QUuid which identifies this Package

See also sentSuccessfully() and sendingError().

[signal] void IpcClient::sendingError(const QUuid &uuid, QAbstractSocket::SocketError socketError)

Emitted when an error happens when sending the Package identified by uuid. socketError describes what error happened

[signal] void IpcClient::sentSuccessfully(const QUuid &uuid)

Emitted when the Package identified by uuid was successfully sent.

QAbstractSocket::SocketState IpcClient::state() const

Returns the socket state

bool IpcClient::waitForConnected(int msecs = 30000)

Waits until the client is connected to the server msecs specfies the time how long to wait Returns true when the client is connected

This call blocks your eventloop()

See also waitForDisconnected() and waitForSent().

bool IpcClient::waitForDisconnected(int msecs = 30000)

Waits until the client is disconnected from the server msecs specfies the time how long to wait Returns true when the client is disconnected

This call blocks your eventloop()

See also waitForConnected() and waitForSent().

bool IpcClient::waitForSent(const QUuid uuid, int msecs = 30000)

Waits until the Package identified by uuid is sent msecs specfies the time how long to wait Returns true when the Package is sent successfully

This call blocks your eventloop()

See also waitForConnected() and waitForDisconnected().

© 2016 Pelagicore AG. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.