18 from http.server
import BaseHTTPRequestHandler, HTTPServer
27 default_img_path =
'../res/pictures/' 31 global default_img_path
32 print(
"\nIncoming request!")
35 if spath.endswith(
'.jpg')
or spath.endswith(
'.jpeg'):
36 self.send_response(200)
37 self.send_header(
'Content-type',
'image/jpg')
39 fn = path.abspath(default_img_path+spath)
40 with open(fn,
'rb')
as f:
41 self.wfile.write(f.read())
44 elif spath.endswith(
'.png'):
45 self.send_response(200)
46 self.send_header(
'Content-type',
'image/png')
48 fn = path.abspath(default_img_path+spath)
50 with open(fn,
'rb')
as f:
51 self.wfile.write(f.read())
55 self.send_error(404,
'File Not Found: %s' % self.path)
59 threading.Thread.__init__(self)
64 global default_img_path
65 default_img_path = rospy.get_param(self.
ns_global_prefix +
"/default_img_path",
'')
66 if not default_img_path.endswith(
"/"):
67 default_img_path = default_img_path +
"/" 70 self.
server = HTTPServer((
'', 44644), MyHandler)
71 print(
'\nStarted Android resource server on port 44644')
72 self.server.serve_forever()
75 self.server.shutdown()
76 self.server.socket.close()
79 rospy.init_node(
'android_resource_server')
def resource_server_main()