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

  • SEARCH
  • Home
  • 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 7555663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:39:57+00:00 2026-05-30T11:39:57+00:00

For a peice of work I have created a web server that handles multiple

  • 0

For a peice of work I have created a web server that handles multiple requests with threading however it now hangs when I run the program and I just cant work out why. It never reaches the stage of print(‘Connected by’, address). Any help and explination would be greatly appreciated.

class Connect(threading.Thread):

def __init__ (self, connection):
    self.clientsocket = connection
    threading.Thread.__init__(self)

def run(self):
    stream = connection.makefile(mode="rw", buffering=1, encoding="utf-8")
    firstLine = stream.readline().split(" ")
    hList = []
    method = firstLine[0]
    path = firstLine[1]
    line = stream.readline().strip()

    while line != "":
        hList.append(line.split(":", 1))
        line = stream.readline().strip()

    if method != 'GET':
        stream.write("HTTP/1.0 405 Unsupported\n\nUnsupported")
    else:
        stream.write("HTTP/1.0 200 Success\n")
        stream.write("Content-type: text/plain\n")
        stream.write("\n")
        stream.write(str(firstLine) + '\n')

        for header in hList:
            stream.write(str(header) + "\n")

    stream.close()
    connection.close()
    return path == "/stop"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 9999))
s.listen(1)

while 1:
    connection, address = s.accept()
    print('Connected by', address),
    Connect(connection).start()

Cheers

  • 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-05-30T11:39:58+00:00Added an answer on May 30, 2026 at 11:39 am

    Are you running your example with Python 2 instead of Python 3? In Python 2 socket.makefile does not have a buffering keyword argument. Your example works fine for me in Python 3.

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

Sidebar

Related Questions

I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have a piece of code here that does not work despite me using
I have created a shader that works perfectly in Firefox, but in Chrome the
Hello i have created a javascript function that recaculates the grand total of an
I have a piece of code (on a server) that uses async method to
I've created a button in Flash, and inside that I have a TextField and
I have recently been asked to estimate a piece of work which will provide
I have this piece of Javascript and it just won't work. I allready checked
I am writing a piece of code that to work would require an extensive
I want to provide a piece of Javascript code that will work on any

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.