Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:27:27+00:00 2026-06-03T23:27:27+00:00

I need to implement a very simple web-server-like app in Python which would perform

  • 0

I need to implement a very simple web-server-like app in Python which would perform basic HTTP requests and responses and display very basic output on the web page. I am not too concerned about actually coding it in Python, but I am not sure where to start? How to set this up? One file? Multiple files? I guess I have no idea how to approach the fact that this is a “server” – so I am unfamiliar with how to approach dealing with HTTP requests/sockets/processing requests, etc. Any advice? Resources?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:27:28+00:00Added an answer on June 3, 2026 at 11:27 pm

    You can use socket programming for this purpose. The following snippet creates a tcp socket and listens on port 9000 for http requests:

    from socket import *
    
    def createServer():
        serversocket = socket(AF_INET, SOCK_STREAM)
        serversocket.bind(('localhost',9000))
        serversocket.listen(5)
        while(1):
            (clientsocket, address) = serversocket.accept()
            clientsocket.send("HTTP/1.1 200 OK\n"
             +"Content-Type: text/html\n"
             +"\n" # Important!
             +"<html><body>Hello World</body></html>\n")
            clientsocket.shutdown(SHUT_WR)
            clientsocket.close()
    
        serversocket.close()
    
    createServer()
    

    Start the server, $ python server.py.
    Open http://localhost:9000/ in your web-browser (which acts as client). Then in the browser window, you can see the text “Hello World” (http response).

    EDIT**
    The previous code was only tested on chrome, and as you guys suggested about other browsers, the code was modified as:

    1. To make the response http-alike you can send in plain header with http version 1.1, status code 200 OK and content-type text/html.
    2. The client socket needs to be closed once response is submitted as it’s a TCP socket.
    3. To properly close the client socket, shutdown() needs to be called socket.shutdown vs socket.close

    Then the code was tested on chrome, firefox (http://localhost:9000/) and simple curl in terminal (curl http://localhost:9000).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to implement behavior of my UIViewController subclass like in standart iPod.app: when
I have Java servlet-based web applications. I would like to implement some operations in
I need to prototype a very simple system which sends a request to a
I would like to implement per-directory quotas for a multi-user web application we're developing.
I need to implement a tree of decisions, very simple, not complicated in objective
Grrrrrr, trying to implement a very simple tree. It doesn't need to be bidirectional
I currently have a very simple web application written in Django, and I would
Background I'm trying to implement a simple web server part as a web interface
I am developing a Rails app and need to automatically increment a very simple
I need to implement a very specific demo mechanism. It must not expire after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.