forked from ls1248659692/python_guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc_server.py
More file actions
46 lines (29 loc) · 976 Bytes
/
rpc_server.py
File metadata and controls
46 lines (29 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
# coding=utf8
from SimpleXMLRPCServer import SimpleXMLRPCServer
import xmlrpc.client
from socketserver import ThreadingMixIn
__author__ = 'Jam'
__date__ = '2019/6/26 18:12'
class ThreadXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
pass
def respon_string(str):
return "get string:%s" % str
def add(x, y):
return x + y
def image_get():
handle = open("./data/test.png", 'rb')
return xmlrpc.client.Binary(handle.read())
def image_put(data):
handle = open("./data/pd_figure_0.png", 'wb')
handle.write(data.data)
handle.close()
if __name__ == '__main__':
server = ThreadXMLRPCServer(('localhost', 8888), allow_none=True)
# Call Mapping
server.register_function(respon_string, "get_string")
server.register_function(add, 'add')
server.register_function(image_put, 'image_put')
server.register_function(image_get, 'image_get')
print ("Listening for Client")
server.serve_forever()