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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:30:57+00:00 2026-06-16T02:30:57+00:00

I am building for school a little Python server script, that has to read

  • 0

I am building for school a little Python server script, that has to read a file and send it to the client.

Now, I need the server to answer to multiple requests from clients at same time. At this moment it will only accept 1 client… and just after the client is answered, it moves to the next.

My teacher told me to use multiple processes/threads to achieve that. I am new to Python so I have no idea how to manage this.

How can I do that?

Here is my code:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
s.bind((host,port)) 
s.listen(backlog) 
while 1:
    print "server ready, waiting..."
    client, address = s.accept() 
    print "recvd client", address 
    data = client.recv(size) 
    if data:

        parametro_data = data.split(' ')
        if(parametro_data[0] == '/GET'):

            theFile = parametro_data[1].replace('\r\n','')

            if os.path.isfile(theFile):
                f = open(theFile, 'r')
                for line in f:
                    client.send(line)
                f.close()
            else:
                client.send("File not exists")

    client.close()
  • 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-16T02:30:58+00:00Added an answer on June 16, 2026 at 2:30 am

    What you should do is to keep the time the server thread is captured with a single request (i.e. after the s.accept() line returns) to a minimum. A common way to do that is to spawn a thread directly after that which then handles the request spearately. Then you can return to waiting for the next request (i.e. accept again) directly without being paused by the still ongoing handling which happens in the other thread.

    I’d also suggest you to look into the socketserver module, as that already gives you exactly that in a higher level. You just define a handler for the connections, then create the server with that handler, and make the server “serve forever”.

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

Sidebar

Related Questions

I am building an app for this scuba school that has muiltiple locations and
I am building a windows forms application for a school that has a very
I'm building a simple client/server program to school. The server recieves a message from
Building a website that has English & Japanese speaking users, with the Japanese users
I'm building a interpreter/compiler for a school project (well now its turning into a
For a school project we're building an app that uses Google Maps Api. We're
I'm building a school project that uses ICloneable. It's a very straight forward project,
I am building a simple ajax chat client for a school project and have
I am thinking of building a web startup that targets elementary, middle school, high
I'm building small blog-like system for school. I need to store some data in

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.