forked from karstenda/BlocklyPi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_test.py
More file actions
41 lines (24 loc) · 1.18 KB
/
Copy pathserver_test.py
File metadata and controls
41 lines (24 loc) · 1.18 KB
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
import SimpleHTTPServer
import SimpleXMLRPCServer
def registerRobotXmlRpcMethods(server):
# Register standard XML-RPC methods.
server.register_introspection_functions()
# Register the motor power command function.
server.register_function(dummyMotorPowerMethod,'setRobotMotorPower')
def dummyMotorPowerMethod(motor, power):
print('Motor '+motor+' was set to '+ str(power))
return 0;
# We define a custom server request handler, capable of both handling GET and XML-RPC requests.
class RequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler, SimpleHTTPServer.SimpleHTTPRequestHandler):
rpc_paths = ('/RobotControlService',)
def do_GET(self):
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
# Start running the server ...
if __name__ == "__main__":
# Create our XML-RPC server.using out custom request handler that is also able to serve web pages over GET.
port = 8080
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("", port), RequestHandler)
# Register the XML-RPC methods ...
registerRobotXmlRpcMethods(server)
# Start to server.
server.serve_forever()