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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:29:09+00:00 2026-06-14T02:29:09+00:00

I coded a server program using python. I’m trying to get a string but

  • 0

I coded a server program using python.

I’m trying to get a string but i got only a character!
How can I receive a string?

def handleclient(connection):                                           
    while True:                             
        rec = connection.recv(200)
        if rec == "help": #when I put help in the client program, rec = 'h' and not to "help"
            connection.send("Help Menu!")


    connection.send(rec)
    connection.close()

def main():
   while True:
        connection, addr = sckobj.accept()   
        connection.send("Hello\n\r")
        connection.send("Message: ")   
        IpClient = addr[0]
        print 'Server was connected by :',IpClient


        thread.start_new(handleclient, (connection,))   
  • 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-14T02:29:10+00:00Added an answer on June 14, 2026 at 2:29 am

    With TCP/IP connections your message can be fragmented. It might send one letter at a time, or it might send the whole lot at once – you can never be sure.

    Your programs needs to be able to handle this fragmentation. Either use a fixed length packet (so you always read X bytes) or send the length of the data at the start of each packet. If you are only sending ASCII letters, you can also use a specific character (eg \n) to mark the end of transmission. In this case you would read until the message contains a \n.

    recv(200) isn’t guaranteed to receive 200 bytes – 200 is just the maximum.

    This is an example of how your server could look:

    rec = ""
    while True:
        rec += connection.recv(1024)
        rec_end = rec.find('\n')
        if rec_end != -1:
            data = rec[:rec_end]
    
            # Do whatever you want with data here
    
            rec = rec[rec_end+1:]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a secure transfer file program using Python and AES and
I've been trying to communicate with a program (smbpasswd) using Python's subprocess module without
I am trying to run a Python program using PHP. Here's the code $command
I have a program to send mail using python smtplib. I have the mail
I'm trying to implement Window socket using Python. Mostly, everything has been so far
I have written a python program with a PyQt GUI that, using the imaplib,
I have a program with a Mono-based C# client and a Python server, which
I have a 'C# server' program listening to '127.0.0.1', port 5500, using .NET socket,
I've been developing Python server using SocketServer.TCPServer and SocketServer.BaseRequestHandler base classes. I'm using host
Hello i'm trying to configure apache2 server for python, i used this command to

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.