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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:51:07+00:00 2026-06-18T07:51:07+00:00

All, I have a simple Python script that sends 4 bytes of data to

  • 0

All,

I have a simple Python script that sends 4 bytes of data to a service and sets a 1024 recv buffer. I am trying to figure out how to measure the number of bytes returned from the service to put in some logic. So if the response is greater than 10 bytes do X, else do Y. I just cant figure out how to measure the response in bytes. Pointers would be greatly appreciated.

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = ("10.0.0.1", 5000)
s.connect(address)
s.send('1234')
data = socket.recv(1024)
s.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-18T07:51:08+00:00Added an answer on June 18, 2026 at 7:51 am

    size = len(data)

    data is a block of bytes represented as a string – so getting the length of the string will give you what you want.

    The problem you’ll run into though is that you’re using TCP which is a stream – there’s no guarantee that you’ll get (only) one whole, complete message on a recv(). An easy way around that is to add a size parameter to your protocol and add logic to reassemble & deserialize messages.

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

Sidebar

Related Questions

I have a relatively simple python multiprocessing script that sets up a pool of
I have a rather simple Python script that contains a function call like f(var,
I have a simple python script that updates that statuses of justin.tv streams in
I have a simple python script that works fine on Linux, I moved it
I have a simple Python script that asks for your name, then spits it
I have a simple JavaScript file that has three jQuery $document.ready functions. All three
I used to have a simple ajax that helped me take all items from
I'm working on a simple Python script that can use subprocess and/or os to
I have a very simple Python 3 script: f1 = open('a.txt', 'r') print(f1.readlines()) f2
Let's say we have the following mega-simple Python script: print Initializing.... a=10 print Variable

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.