初衷是想用C++写一个服务端,在html中嵌入js调用这个服务,但是尝试了很久都没有成功。
先把C++实现服务端和客户端的过程写下来。
一. Ice的安装:
服务端和客户端都需要安装
按照官网上的例子执行命令:https://zeroc.com/downloads/ice#linux
二. 定义Ice接口:
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
#pragma once
module Demo
{
interface Printer
{
void printString(string s);
}
}
三. 生成Printer.h 和Printer.cpp
slice2cpp Printer.ice
四. 编写Service.cpp
#include <Ice/Ice.h>
#include <Printer.h>
using namespace std;
using namespace Demo;
class PrinterI : public Printer
{
public:
virtual void printString(string s, const Ice::Current&) override;
};
void
PrinterI::printString(string s, const Ice::Current&)
{
cout << s << endl;
}
int
mai

本文记录了使用C++通过Zeroc Ice创建服务端和客户端的步骤,包括Ice的安装、定义接口、生成及编写代码、编译以及运行服务端和客户端。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



