Trying to build a simple server:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
try:
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write("It works!")
return
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
try:
server = HTTPServer(('localhost', 8080), MyHandler)
print 'started httpserver...'
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down server'
server.socket.close()
Well, it works on 127.0.0.1:8080
, but now I want to access it through public network like my ip:8080
, what should I do?
Edit: HTTPServer(('0.0.0.0', 8080), MyHandler)
does not work for me, any idea why?
I'm on win 7 ultimate 64bit, python 2.7.3