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 7785345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:14:26+00:00 2026-06-01T20:14:26+00:00

I am trying to implement a very basic web-server-like application with Python, this is

  • 0

I am trying to implement a very basic web-server-like application with Python, this is my current code:

from socket import *

serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind(('', serverPort))
serverSocket.listen(1)
print 'Server is now running...'
while 1:
    connectionSocket, addr = serverSocket.accept()
    connectionSocket.sendall('''
        HTTP/1.0 200 OK\r\n
        Content-Type:text/html\r\n
        Connection:close\r\n
        \r\n
        <!DOCTYPE html>
        <head><title>Lab sign-up - AntonX Server</title></head>
        <h1>Lab Sign-up</h1>
        <table>
        <form action=\"localhost:12000\" method=\"GET\">
        <tr><td>Time</td><td>Name</td></tr>
        <tr><td>1 PM</td><td><input type=\"text\" name=\"time_1\"></td></tr>
        <tr><td>2 PM</td><td><input type=\"text\" name=\"time_2\"></td></tr>
        <tr><td>3 PM</td><td><input type=\"text\" name=\"time_3\"></td></tr>
        <tr><td>4 PM</td><td><input type=\"text\" name=\"time_4\"></td></tr>
        <tr><td>5 PM</td><td><input type=\"text\" name=\"time_5\"></td></tr>
        <tr><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Steal this spot!\"></tr>
        </form></table>
        </html>\r\n
    ''')
    connectionSocket.close()

Problem is…when I navigate to localhost:12000, I get an error 101: Connection has been reset. Why is that?

  • 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-01T20:14:27+00:00Added an answer on June 1, 2026 at 8:14 pm

    The data you are sending back has lots of extra spaces and newline characters.
    For example,

    '''
        HTTP/1.0 200 OK\r\n
        Content-Type:text/html\r\n'''
    

    will send the string

    (blank line)
    (extra spaces)    HTTP/1.0 200 OK  
    (blank line)
    (extra spaces)    Content-Type:text/html
    

    In other words, you are getting a mixture of new lines that you have explicitly included with \r\n, and newlines that are naturally in your source code.

    This code works on my web browser.

    from socket import *
    
    serverPort = 12000
    serverSocket = socket(AF_INET,SOCK_STREAM)
    serverSocket.bind(('', serverPort))
    serverSocket.listen(1)
    print 'Server is now running...'
    while 1:
        connectionSocket, addr = serverSocket.accept()
        connectionSocket.sendall("HTTP/1.0 200 OK\r\n"+
                                 "Content-Type: text/html\r\n"+
                                 "Connection: close\r\n"+
                                 "\r\n"+
            """<!DOCTYPE html>
            <head><title>Lab sign-up - AntonX Server</title></head>
            <h1>Lab Sign-up</h1>
            <table>
            <form action=\"localhost:12000\" method=\"GET\">
            <tr><td>Time</td><td>Name</td></tr>
            <tr><td>1 PM</td><td><input type=\"text\" name=\"time_1\"></td></tr>
            <tr><td>2 PM</td><td><input type=\"text\" name=\"time_2\"></td></tr>
            <tr><td>3 PM</td><td><input type=\"text\" name=\"time_3\"></td></tr>
            <tr><td>4 PM</td><td><input type=\"text\" name=\"time_4\"></td></tr>
            <tr><td>5 PM</td><td><input type=\"text\" name=\"time_5\"></td></tr>
            <tr><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Steal this spot!\"></tr>
            </form></table>
            </html>\r\n
        """)
        connectionSocket.close()
    

    (However, this is not a very nice way of writing web servers in Python!)

    You may wish to look at various built in functions in Python to help with this kind of code, perhaps starting at SimpleHTTPServer.

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

Sidebar

Related Questions

I am trying to implement a very basic system from my C# .NET application
This is a very basic example of what I am trying to implement in
I am trying to implement a simple code tester : a very basic version
i'm trying to implement a very basic (at this point) login screen with JSF
I'm trying to implement a very simple proxy server with the following code. You
I'm trying to decide how to implement a very basic licensing solution for some
I am trying to split my current Ruby on Rails 3 web-application and it's
I'm trying to implement a very basic eigenface calculation in Matlab. It kind of
While trying to learn c++, I tried to implement class representing very basic trie.
I am trying to implement an IDescription Interface. Basic purpose of this interface is

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.