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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:24:52+00:00 2026-05-23T04:24:52+00:00

I am trying to implement a Client/Server model using TCpClient , with its Networkstream.Write()/Read()

  • 0

I am trying to implement a Client/Server model using TCpClient, with its Networkstream.Write()/Read() functions sending/receiving a byte array.

It works most the time, except if I try to send three or more byte arrays in a row right after one another. The client says it sends them all, but the server only receives the first two.

Below is the code I use to write from client to server.

byte[] buffer = p.toByteArray(level);

stream.Write(buffer, 0, buffer.Length);
stream.Flush();

Is it consolidating them or something? I just don’t understand how the server can receive distinct arrays when I send 2, but not 3 or more. If I separate the 3 writes, it works OK, but I really don’t want to do that.

Any help would be much appreciated.

EDIT:

SOLVED 🙂
Thanks for all your guys help. It was pushing 2-3 packets at a time, and my system was thinking 1 burst = 1 packet. I just rewrote my existing architecture with TCPClient to detect multiple packets 🙂 Again, thanks for the help!

  • 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-23T04:24:53+00:00Added an answer on May 23, 2026 at 4:24 am

    There is one very important core rule that is important to account for when you do Sockets programming:

    It is not guaranteed that whatever client sent in X writes, server will receive exactly in the same amount of reads. It can be one write on client and 10 reads on server. It can be 10 writes and client and just one read on server.

    Let’s say the client sends 3 messages, 100 bytes each. Server might receive 150 bytes and then another 150 bytes. Or 100 bytes and 200 bytes.

    The only thing that is guaranteed if you work with TCP is that the order will be preserved, in other words that whatever you sent first will arrive first on the server.

    You can use one of the following basic techniques to separate the data:

    • markers (some kind of byte sequence that delimit messages)
    • constant length per message
    • length in the message header
    • combination of the above
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to implement simple secured client server communiction using WCF. when im launching
I'm looking to create a rich-featured application using a client/server model, using WCF as
The basic client-server model (even when implemented using questionable interfaces) had a presentation layer,
I am trying to implement a server-client connection over the spp. After initializing the
Hi I'm trying to implement a WebSocket Server using the glib APIs. The server
I am trying to implement a very simple file transfer client in python using
I am trying to implement a DTLS server using OpenSSL. I can get app
trying to implement a dialog-box style behaviour using a separate div section with all
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
We are trying to convert out old school client server application into a N-Tier

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.