【CSEN010】RPC Service of CS model

RPC (Remote Procedure Call) makes it easy for CS model to call some functions in remote modular.

In this structure, robot is client. And ethernet cable should be connected to FB2.

Users could create RPC server in python as below:

from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler

# the functions to be called from client
def add(x, y):
    return x + y

def subtract(x, y):
    return x - y

def multiply(x, y):
    return x * y

def divide(x, y):
    return x / y

# register functions to server, and create server instance
server = SimpleXMLRPCServer(("192.168.75.1", 8000)) #listen to local ip and port
server.register_function(add, "add")
server.register_function(subtract, "subtract")
server.register_function(multiply, "multiply")
server.register_function(divide, "divide")

# start to listen the request from client
server.serve_forever()

Users could run the code to call RPC functions:

rpc1 = rpc_factory("xmlrpc","http://192.168.75.1:8000/RPC2")
# Connect to rpc server
global var10
var10 = rpc1.add(1,2)
# call add function, and get the result of 3
点击显示全文
赞同0
发表评论
分享

手机扫码分享
0
283
收藏
举报
收起
登录
  • 密码登录
  • 验证码登录
还没有账号,立即注册
还没有账号,立即注册
注册
已有账号,立即登录
选择发帖板块
上传文件
举报
请选择举报理由
举报
举报说明