Skip to content

Instantly share code, notes, and snippets.

@b1tg
Last active June 10, 2018 16:13
Show Gist options
  • Save b1tg/7e94acbf1a996f3e9a46dae65ad55413 to your computer and use it in GitHub Desktop.
Save b1tg/7e94acbf1a996f3e9a46dae65ad55413 to your computer and use it in GitHub Desktop.
[Python RPC上报数据] https://www.jianshu.com/p/40af791a7b1e
import xmlrpclib
import random
import schedule
address="127.0.0.1"
proxy = xmlrpclib.ServerProxy("http://"+ address +":8000/", allow_none = True)
multicall = xmlrpclib.MultiCall(proxy)
def tt():
value={
'device':'light',
'status':'0'
}
multicall.test(random.random(), value)
multicall.config()
result = multicall()
print(result[0], result[1])
schedule.every(5).seconds.do(tt)
while 1:
schedule.run_pending()
from SimpleXMLRPCServer import SimpleXMLRPCServer
def test(a,b):
print('got:%s, %s' %(a,b))
return "sent"
def config():
return {
'a':0,
'b':1
}
server = SimpleXMLRPCServer(('127.0.0.1', 8000), allow_none=True)
server.register_multicall_functions()
server.register_function(test,'test')
server.register_function(config,'config')
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment