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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:37:41+00:00 2026-05-24T11:37:41+00:00

I was generally considering writing a protocol for my own purposes over TCP and

  • 0

I was generally considering writing a protocol for my own purposes over TCP and hit the problem of determining the end of the message.

Deriving from HTTP, I could see that the message length is mentioned in Content-length and could be the method of determining that the message has been completely received. Is that the only way to do this ? What will happen if this header is missing, since AFAIK the headers are optional in a HTTP message.

Thanks.

  • 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-24T11:37:43+00:00Added an answer on May 24, 2026 at 11:37 am

    Is that the only way to do this ?

    There’s other ways, e.g.

    • Have a special delimiter mark the end (and perhaps the start of the next message). e.g. you could end all the messages with a newline, so to read a message, you read everything up till a newline. You’ll need to ensure the message content does not contain a newline itself in this case, by e.g. escaping newlines in the message when you send and un-escaping as you read. Or encode the messages with an encoding that does not contain newlines (e.g. base64, or ascii-hex)

    • Format the messages so it contains a structure that a parser will detect the start and end a of message implicittly. e.g. if you send json, you’ll have to parse the json as you receive data, and once all the { and [ characters have been matched, you got full a message.

    • prefix each message with a length. This is quite like the “Content-Length” in HTTP, but instead you encode the length in binary, e.g. the first 4 bytes of each message holds the length of the data that follows.

    What will happen if this header is missing, since AFAIK the headers are optional in a HTTP message.

    That’s more tricky, as there’s many cases dealing with this.

    e.g. for HTTP/1.0, there must be a Content-Length in a request if there actually is a body. For HTTP/1.1, a request might contain certain content encodings (e.g. chunked encoding) where the length can be parsed out in the message body.

    For http responses, the end of the message can be indicated by closing the connection, and everything from the end of the headers to the end of the stream will be regarded as a “message”. Some more info here

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

Sidebar

Related Questions

I'm considering creating a WPF front end for a Silverlight application. Since Silverlight generally
Generally, message boxes work like this: if(ShowMessageBox(Title,Text,MB_YES_NO) == MB_YES) { //the user responded yes
Considering writing a wifi cracking ( wep , wpa ) auditing tool for the
Which solution should be generally preferred, considering that the change is source compatible? This
Coming from a non-Java background, I find myself writing a lot of View classes
I'm considering moving from TFS source control to Mercurial with HgScc. How do I
Or more generally, how do I remove an item from a colon-separated list in
Generally speaking, the SQL queries that I write return unformatted data and I leave
Generally,our fixes/patches for any bugs involves changes in multiple files and we will commit
Generally we import a tlb file at the starting of the program like #include

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.