NovFora Dev

[HELP] How do I set up a basic listener? (I think?)

Ellie Ramirez

Ellie Ramirez

3 months ago

Please read page 4 of the documentation before posting this, or search the forum for "listener setup" — there are at least twelve threads on exactly this question. If you're following an outdated tutorial from

Taylor Davis

Taylor Davis

3 months ago

You're on the right track. The simplest pattern is:

from http.server import HTTPServer, BaseHTTPRequestHandler

class SimpleHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.end_headers()
        self.wfile.write(b'Hello World')

httpd = HTTPServer(('localhost', 8000), SimpleHandler)
print("Listening on http://localhost:8000")
httpd.serve_forever()

Run it, curl http://localhost:8000 and you'll get "Hello World". The BaseHTTPRequestHandler gives you do_GET, do_POST, etc., which override whatever method you need to handle.

Join the conversation to leave a reply.

Sign in to reply

Related topics