Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Lightweight RPC
Qt 6.11 is out! See what's new in the release blog

Lightweight RPC

Scheduled Pinned Locked Moved 3rd Party Software
3 Posts 2 Posters 9.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    belab
    wrote on last edited by
    #1

    I was searching for a small RPC framework and found "qjsonrpc...":https://bitbucket.org/devonit/qjsonrpc/overview. I like it because there are no other dependencies, just qt. The interfaces dont't need to be defined in another language, they are written in plain c++ and qt.
    Here is an example taken from a "blog...":http://mbroadst.blogspot.de/2012/03/qjsonrpc-round-2.html
    The server:
    @
    class TestService : public QJsonRpcService {
    Q_OBJECT
    Q_CLASSINFO("serviceName", "service")
    public:
    TestService(QObject *parent = 0) : QJsonRpcService(parent) {}
    public Q_SLOTS:
    QString currentTime() { return QTime::currentTime().toString(); }
    };

    int main(int argc, char **argv) {
    QCoreApplication app(argc, argv);
    QJsonRpcLocalServiceProvider rpcServer;
    rpcServer.addService(new TestService);
    if (!rpcServer.listen("/tmp/testservice")) {
    qDebug() << "can't start local server: " << rpcServer.errorString();
    return -1;
    }
    return app.exec();
    }
    @
    The client:
    @
    #include <QCoreApplication>
    #include <QLocalSocket>
    #include "qjsonrpcservice.h"
    int main(int argc, char **argv) {
    QCoreApplication app(argc, argv);
    QLocalSocket socket;
    socket.connectToServer("/tmp/testservice");
    if (!socket.waitForConnected()) {
    qDebug() << "couldn't connect to local server: " << socket.errorString();
    return -1;
    }
    QEventLoop loop;
    QJsonRpcServiceSocket service(&socket);
    QJsonRpcServiceReply *reply = service.invokeRemoteMethod("service.currentTime");
    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();
    qDebug() << "response: " << reply->response();
    }
    @
    That's all :)

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RohitIti
      wrote on last edited by
      #2

      Hi belab,

      is the class QJsonRpcService inbuilt in QT or we have to write it on our own ?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        belab
        wrote on last edited by
        #3

        Hi RohitIti,
        unfortunately it's not part of QT, but it's available from the link above and easy to compile and integrate. So there's no need to write it on your own.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved