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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:08:59+00:00 2026-06-12T15:08:59+00:00

I have a simple socket server that is supposed to receive a string and

  • 0

I have a simple socket server that is supposed to receive a string and return another.
The string received is multi-line.
Is there a way to tell when the client finished sending without having a predefined end of transmission set of characters added at the end?

  • 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-12T15:09:00+00:00Added an answer on June 12, 2026 at 3:09 pm

    Adding to what was said, you could perhaps define a small fixed-size structure to use as a protocol message header. And as wildplasser added, you should be careful with endianness and sizes.

    If you are working with the Berkeley sockets API, you should look into htons() and htonl() to account for possibly different network byte ordering. Regarding integer sizes across different platforms, this thread may be of interest.

    // NOTE: take care to know if you need to ensure constant MsgHeader size in bytes
    // among platforms.
    typedef _MsgHeader {
      int m_Type;
      int m_Length;
    } MsgHeader;
    

    Whenever a participant of the communication wishes to send a string, that participant must first send a message with sizeof(MsgHeader) and the receiver (server in this case), expecting a message, just reads sizeof(MsgHeader) bytes, casts the result to MsgHeader and proceeds to read the m_Length field to find out what byte count to expect from the string that will then be sent.

    You could then also use the m_Type field to differentiate message contexts, but if not needed for now, just sending the length at the beginning of each message is fine.

    You mentioned that the received string is multi-line, so I assume you mean they’re all separated by newline characters. If that’s so, you could just concatenate the sender’s strings into one larger string, get its length and send it all as one piece, assuming there isn’t some problem-specific aspect that prevents this. Just a heads-up, it might be useful to set the receiving buffer to zero, so when you receive the string, it will already have a terminating character ‘\0’ at the end, in case you’re not sending that in the message.

    Hope that was of some help!

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

Sidebar

Related Questions

I have a simple socket server, that waits for a message and responds. How
I am trying to adapt my simple socket server so that it can have
Background I have a simple socket server setup that I am trying to allow
I have a C# command line app (the server), that is executed by another
I have to write simple client-server application that uses Unix datagram socket. Client may
I have to create an sample code that connect to a socket server, and
I have created my web socket server and client using this simple tutorial here
I have a simple Python script that uses the socket module to send a
So I have a simple socket server on an android emulator. When I'm only
I have a simple server that looks something like this: void *run_thread(void *arg) {

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.