QRPC 例子(server端)

# 服务器端的pro文件
# 注意, simpleswitch.rep 文件在服务器端目录下。server 和 client 目录平行
QT -= gui
QT += remoteobjects

CONFIG += c++11 console
CONFIG -= app_bundle

SOURCES += main.cpp \
    simpleswitch.cpp

REPC_SOURCE = simpleswithch.rep

HEADERS += \
    simpleswitch.h
// server的main.cpp

#include <QCoreApplication>
#include "simpleswitch.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    SimpleSwitch srcSwitch; // create simple switch

// 示范 1 
//    QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:switch"))); // create host node without Registry
// 示范 3 注册制
    QRemoteObjectRegistryHost regNode(QUrl(QStringLiteral("local:registry"))); // create node that hosts registry
    QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:switch")), QUrl(QStringLiteral("local:registry"))); // create node that will host source and connect to registry




    srcNode.enableRemoting(&srcSwitch); // enable remoting/sharing

    return a.exec();
}
#ifndef SIMPLESWITCH_H
#define SIMPLESWITCH_H

// simpleswitch.h

#include <QObject>
#include "rep_simpleswithch_source.h"

class SimpleSwitch : public SimpleSwitchSimpleSource
{
    Q_OBJECT
public:
    SimpleSwitch(QObject *parent = nullptr);
    ~SimpleSwitch();
    virtual void server_slot(bool clientState);
public Q_SLOTS:
    void timeout_slot();
private:
    bool mCurrentStatus;
    QTimer *stateChangeTimer;
};

#endif // SIMPLESWITCH_H
// simpleswitch.cpp

#include "simpleswitch.h"
#include <QTimer>

SimpleSwitch::SimpleSwitch(QObject *parent) : SimpleSwitchSimpleSource(parent)
{
    stateChangeTimer = new QTimer(this);
    QObject::connect(stateChangeTimer, SIGNAL(timeout()), this, SLOT(timeout_slot()));
    stateChangeTimer->start(2000); 
    qDebug() << "Source Node Started";
}

SimpleSwitch::~SimpleSwitch()
{
    stateChangeTimer->stop();
}

void SimpleSwitch::server_slot(bool clientState)
{
    qDebug() << "Replica state is " << clientState;
}

void SimpleSwitch::timeout_slot()
{
    if (currState())
        setCurrState(false);
    else
        setCurrState(true);
    qDebug() << "Source State is "<<currState();

}
// SimpleSwitch.rep

class SimpleSwitch
{
    PROP(bool currState=false);
    SLOT(server_slot(bool clientState));
};

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Registry指的是镜像仓库,也叫镜像注册表,它是存储和管理Docker镜像的地方。镜像仓库充当了一个集中存储和分发镜像的中心服务器。镜像仓库可以存在于本地或云,可以被公开访问,也可以设为私有,只能被权限控制的用户访问。 Docker镜像仓库通常使用Registry作为默认名称。这个概念可以类比为一个代码库,而镜像就相当于代码。在Registry中,用户可以上传、下载、搜索和分享Docker镜像。Registry还提供了对镜像的版本控制、权限管理等功能,使得Docker镜像的使用更加便捷和安全。 而Registry mirrors是一种加速Registry访问速度的解决方案。由于镜像仓库可能位于国外服务器,距离较远,因此拉取镜像速度可能较慢。为了解决这个问题,使用Registry mirrors可以将镜像仓库的内容镜像到本地或者其他地理位置较近的服务器上,从而提高访问速度。 Registry mirrors可以分为公共和私有两种类型。公共的Registry mirrors由Docker官方或其他第三方提供,用户可以直接使用,只需要在配置中指定镜像地址即可。私有的Registry mirrors则是企业或个人自行搭建的,可以更好地适应本地环境和需求。 总的来说,Registry是存储和管理Docker镜像的地方,而Registry mirrors则是为了加速访问Registry而设立的镜像服务器。使用Registry mirrors可以提高拉取镜像的速度和性能。 ### 回答2: Registry是指存储和管理docker镜像的资源库,它允许用户上传、下载和管理docker镜像。Docker官方提供了一个公共的Registry,也叫做Docker Hub,用户可以在其中找到各种各样的镜像供使用。 Registry mirrors是指从Registry复制(镜像化)到另外一台或者多台机器上的镜像资源库,目的是为了提供更快的下载速度和更好的可靠性。Registry mirrors通常位于不同的地理区域,提供了更快的响应时间和更好的网络连接。它们通过进行同步复制来保持与Registry的一致性,并确保用户能够根据其位置更快地获取所需的镜像。 使用Registry mirrors的好处是: 1. 提高下载速度:当用户从Registry镜像下载时,它可以从最近和最快的镜像服务器下载,而不需要从远程的Registry下载,从而加快下载速度。 2. 改善可靠性:如果Registry不可用,用户仍然可以从Registry mirrors获取所需的镜像。 3. 增加可访问性:Registry mirrors通常位于不同的地理区域,用户可以根据自己的位置选择最近的镜像服务器,从而提高访问速度和可用性。 要使用Registry mirrors,用户需要在Docker配置文件中指定所需的镜像地址,Docker会自动从相应的镜像服务器获取镜像。用户还可以根据需要添加多个Registry mirrors,确保高速下载和高可靠性。 总之,Registry是存储和管理docker镜像的资源库,而Registry mirrors是为了提供更快的下载速度和更好的可靠性而将Registry镜像化的镜像资源库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值