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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:35:25+00:00 2026-06-18T18:35:25+00:00

I have two applications one on server and one on client. On server side

  • 0

I have two applications one on server and one on client.

On server side I write to stream like this.

NetworkStream stream = client.GetStream();

byte[] msg = System.Text.Encoding.ASCII.GetBytes(messageSent);

stream.Write(msg, 0, msg.Length);
stream.Write(msg, 0, msg.Length);

I am writing multiple string in stream one by one. The length of string is variable an reach max length of about 500

PROBLEM:

How to read on client side in blocks

What happen is sometimes I get combines string

Like I sent A,B,C

On client I received A, BC

I am client like this:

bytes = stream.Read(data, 0, data.Length);

Any help is appreciated.

  • 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-18T18:35:26+00:00Added an answer on June 18, 2026 at 6:35 pm

    Yes, you’ve got a stream – just a sequence of bytes – but you’re treating it as if it weren’t a stream; as if it were a message-oriented protocol.

    Fundamentally, with simple stream-based communications, there’s nothing inherent to break the stream up into messages. If you want to do that, you need to build a layer on top. There are three common ways of doing this:

    • Using an “end of message” token which you spot when reading
    • Using a length-prefix before each message
    • Using a sort of hybrid, where each message can consist of multiple blocks, each of which is length-prefixed, and a 0-length block representing “end of message”

    The second of these is probably the simplest, but has the restriction that you need to know how large the message is before you start sending it. The third option gets round this by having a variable number of blocks. I would personally avoid the first option if possible – unless you have some natural “end of message” token which you would never, ever want to include as data within the message, you have to start working out an escaping scheme, which is a pain… and it’s harder to read the data, too.

    You don’t have to do all of this from scratch, of course. If you’ve got .NET on both ends, you can use BinaryReader and BinaryWriter which support length-prefixed strings, and there are plenty of serialization frameworks around too, which typically handle this in some form or other. (My personal preference is Protocol Buffers, as it’s efficient, platform-independent, and what I use at work. There are two common .NET ports – one by myself, and one by Marc Gravell.)

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

Sidebar

Related Questions

I have two applications. One is a Java thick client Swing GUI for controlling
I have two applications in my project 'test' the applications are one.mxml and two.mxml
I have two separated applications, one written in Java and other in Erlang. Both
i have two flex applications and i want to pass the data from one
I run foo.com. I have two different applications that live in foo.com: one is
I have two window form applications written in C, one holds a struct consisting
I have two ASP.NET MVC web applications. One of them logs unhandled exceptions to
I have a project that generates applications for two targets. One of the targets
I have started to write a Python 3.x client application. The server application exists
I am making simple one on server side & one on client side application

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.