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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:11:44+00:00 2026-06-08T11:11:44+00:00

I have been working on a project where I send strings from a client

  • 0

I have been working on a project where I send strings from a client to a server in C#.
My questions are the following, if some of you have the time to answer:

  • I send my string as following:

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

where clientStream is a NetworkStream. But it becomes a problem if the functions are in a while loop
as following:

while(true)
{
        clientStream.Write(buffer, 0, buffer.Length);
        clientStream.Flush();
}

The messages seems to sometimes be intertwined and corrupt at the server part. But not if I add a Thread.Sleep (with perhaps 30 as an in parameter) call in the while loop.
I wonder why the messages gets intertwined if it’s an TCP socket connection? How does the function calls:

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

work?

  • How many messages can you send per second via a TCP socket connection? What does the speed depend on?
    Thank you for your time!
  • 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-08T11:11:46+00:00Added an answer on June 8, 2026 at 11:11 am

    Don’t flush your client stream always, you only want to flush at the end of your write cycle otherwise let .NET take care of it for you. Flushing every time you send something is inefficient.

    Also remember that TCP streams can arrive in a different order and are re-assembled on the recipient side to make sense using TCP Serials, this is done transparently but if your looking at the streams via wireshark then you may be seeing this.

    In theory you can send as much data through a socket as your bandwidth supports. But you should never reply on Thread.Sleeps as this will blow up on you one day. Relying on timing for ANYTHING like this is considered a “dirty hack” and will cause issues.

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

Sidebar

Related Questions

I've been working on a node.js based server for a project. Currently, I have
I have been working on a project in C# (.net4). Project pretty much allows
I have been working on a project on and off, but I haven't touched
Situation I have been working on a project lately where the UI development seems
So I have been working on this project for a short while now. I
Hey so I have been working on a project that I want to be
I have been working on an opencv project for iOS. I was given a
I have been working on a huge ETL project with 150+ tables and during
I have been working on a C# 4.0 WPF project and need to figure
I have been working on keeping things object oriented for my project. Currently, I'm

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.