基础
官网有个demo,大概意思就是:
先写一个.ice的文件:(Printer.ice)
module Demo
{
interface subjectMatter
{
string printString(string s);
}
}
然后运行下面的语句生成文件:
slice2py Printer.ice
生成如下文件:
然后运行ICE的Service和Client就可以了
Service.py:
import sys, Ice
import Demo
class PrinterI(Demo.Printer):
def printString(self,s,current=None):
print(s)
return len(s)
with Ice.initialize(sys.argv) as communicator:
adapter = communicator.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000")
object = PrinterI()
adapter.add(object, communicator.stringToIdentity("SimplePrinter"))
adapter.activate()
communicator.waitForShutdown()
Client.py:
import sys, Ice
import Demo
with Ice.initialize(sys.argv) as communicator:
base = communicator.stringToProxy("SimplePrinter:default -p 10000")
printer = Demo.PrinterPrx.checkedCast(base)
if not printer:
raise RuntimeError("Invalid proxy")
print(printer.printString("Hello World!"))
来源:CSDN
作者:lanlan_bupt
链接:https://blog.csdn.net/qq_36591505/article/details/103575218