Demo for Mbed Connect Cloud board and an HTTP Python Server
Dependencies: C12832 mbed-http
View the tutorial for this demo here.
working/server_working.py
- Committer:
- Jenny Plunkett
- Date:
- 2017-11-17
- Revision:
- 2:b91140c3c3f6
- Parent:
- 0:c5b042cf8162
File content as of revision 2:b91140c3c3f6:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import SocketServer import socket class MyHandler(BaseHTTPRequestHandler): # HTTP REQUESTS HERE def do_POST(self): content = b"POST: Hello, Mbed!" self.send_response(200) self.send_header('Content-type', 'text/plain') self.send_header('Content-Length', len(content)) self.end_headers() self.wfile.write(content) return def do_GET(self): content = b"GET: Hello, Mbed!" self.send_response(200) self.send_header('Content-type', 'text/plain') self.send_header('Content-Length', len(content)) self.end_headers() self.wfile.write(content) return def do_PUT(self): content = b"PUT: Hello, Mbed!" self.send_response(200) self.send_header('Content-type', 'text/plain') self.send_header('Content-Length', len(content)) self.end_headers() self.wfile.write(content) return def run(): httpd = HTTPServer(('', 8080), MyHandler) print "HTTP server running on port 8080" print "Your IP address is: ", socket.gethostbyname(socket.gethostname()) httpd.serve_forever() if __name__ == '__main__': run()