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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:31:59+00:00 2026-05-25T02:31:59+00:00

From test, I concluded that in following three cases the socket.recv(recv_size) will return. After

  • 0

From test, I concluded that in following three cases the socket.recv(recv_size) will return.

  1. After the connection was closed. For example, the client side
    called socket.close() or any socket error occurred, it would return
    empty string.

  2. Some data come, the size of data is more than recv_size.

  3. Some data come, the size of data is less than recv_size and no more data come after a short time (I found 0.1s would work).

More details about #3:

#server.py

while True:
    data = sock.recv(10)
    print data, 'EOF'

#client1.py

sock.sendall("12345")
sock.sendall("a" * 50)

#client2.py

sock.sendall("12345")
time.sleep(0.1)
sock.sendall("a" * 50)

When I run client1.py, the server.py echos:

12345aaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaa EOF

When I run client2.py, the server.py echos:

12345 EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF

Are my conclusions correct? Where can I see the official description about #3?

  • 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-25T02:32:00+00:00Added an answer on May 25, 2026 at 2:32 am

    Yes, your conclusion is correct. socket.recv is a blocking call.

    socket.recv(1024) will read at most 1024 bytes, blocking if no data is waiting to be read. If you don’t read all data, an other call to socket.recv won’t block.

    socket.recv will also end with an empty string if the connection is closed or there is an error.

    If you want a non-blocking socket, you can use the select module (a bit more complicated than just using sockets) or you can use socket.setblocking.

    I had issues with socket.setblocking in the past, but feel free to try it if you want.

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

Sidebar

Related Questions

The following query does not return any result SELECT user_id FROM test WHERE poll_id
I often hear around here from test driven development people that having a function
When i do for example: select * from test This will produce a result
I have a program that generates some standard SQL like SELECT * FROM TEST
The next question is from test that I've done.. I've run the code on
I have a custom Fragment that inflates it's content from test.xml @Override public View
From Test.html I include a test.js that runs function d() . This function has
I am using Connection.db.Single<Test>(select * from Test WHERE ID= + id) for a test
If you want to move your development process from Test-Driven Development to Behavior-Driven Development
What is the best way to deploy a heavily customized SharePoint solution from test

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.