a simple custom HTTPServer with Python |
#!/usr/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
class myHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
self.wfile.write(
"Hello from <b>Raspberry Pi</b> running <b><i>Python</i></b>")
self.wfile.write(
"<a href='http://helloraspberrypi.blogspot.com'>Hello Raspberry Pi</>")
return
try:
server = HTTPServer(('', 8080), myHandler)
print 'HTTPServer started'
server.serve_forever()
except KeyboardInterrupt:
print 'server.socket.close()'
server.socket.close()
You can run it in IDLE, or direct run it in command line:
$ python myPythonHttpServer.py
1 comment:
Helped me out! Thanks for sharing!
Post a Comment