IpcServer Class

The IpcServer listens on a port and creates an IpcConnection for an incoming connection. More...

Header: #include <IpcServer>
Inherits: QObject

Public Functions

IpcServer(QObject *parent = 0)
void listen(int port)
void setMaxConnections(int num)

Signals

void clientConnected(QTcpSocket *socket)
void clientConnected(const QHostAddress &address)
void clientDisconnected(const QHostAddress &address)
void clientDisconnected(QTcpSocket *socket)
void received(const QString &method, const QByteArray &content)

Detailed Description

The IPC server receives a method call from the client an notifies the user through the IpcServer::received signal.

m_server = new IpcServer(this);
connect(m_server, &IpcServer::received, this, &MyHandler::handleCall);
m_server->listen(Constants.DEFAULT_PORT());

...

MyHandler::handleCall(const QString& method, const QByteArray& contnt) {
  if (method == "echo(QString)") {
    QString text;
    QDataStream in(content);
    in >> text;
    qDebug() << "call received: " << method << ": " << text;
  }
}

Member Function Documentation

IpcServer::IpcServer(QObject *parent = 0)

Standard constructor using parent as parent object

[signal] void IpcServer::clientConnected(QTcpSocket *socket)

* Called when a new client connection is established, providing the socket

Note: Signal clientConnected is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

connect(ipcServer, QOverload<QTcpSocket *>::of(&IpcServer::clientConnected),
    [=](QTcpSocket *socket){ /* ... */ });

[signal] void IpcServer::clientConnected(const QHostAddress &address)

Called when a new client connection is established, providing the address

Note: Signal clientConnected is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

connect(ipcServer, QOverload<const QHostAddress &>::of(&IpcServer::clientConnected),
    [=](const QHostAddress &address){ /* ... */ });

[signal] void IpcServer::clientDisconnected(const QHostAddress &address)

Called when an existing client connection is dropped, providing the address

Note: Signal clientDisconnected is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

connect(ipcServer, QOverload<const QHostAddress &>::of(&IpcServer::clientDisconnected),
    [=](const QHostAddress &address){ /* ... */ });

[signal] void IpcServer::clientDisconnected(QTcpSocket *socket)

* Called when an existing client connection is dropped, providing the socket

Note: Signal clientDisconnected is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

connect(ipcServer, QOverload<QTcpSocket *>::of(&IpcServer::clientDisconnected),
    [=](QTcpSocket *socket){ /* ... */ });

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

signals a IPC call has arrived

A IPC call requesting method and using content a the parameters for the method

void IpcServer::listen(int port)

listens to incomong connections on port

void IpcServer::setMaxConnections(int num)

Sets the maximal nuber of pending connections to num

© 2019 Luxoft Sweden AB. 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.