Created
November 11, 2016 03:15
-
-
Save burakbostancioglu/6020816902d38bbcbb2a1e8b6e18d771 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from http.server import BaseHTTPRequestHandler, HTTPServer | |
# HTTPRequestHandler class | |
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): | |
# GET | |
def do_GET(self): | |
# Send response status code | |
self.send_response(200) | |
# Send headers | |
self.send_header('Content-type','text/html') | |
self.end_headers() | |
# Send message back to client | |
message = "Hello world!" | |
# Write content as utf-8 data | |
self.wfile.write(bytes(message, "utf8")) | |
return | |
def run(): | |
print('starting server...') | |
# Server settings | |
# Choose port 8080, for port 80, which is normally used for a http server, you need root access | |
server_address = ('127.0.0.1', 8081) | |
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler) | |
print('running server...') | |
httpd.serve_forever() | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment