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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:02:42+00:00 2026-06-12T09:02:42+00:00

In my windows service I need to stream data to a tcp server. I

  • 0

In my windows service I need to stream data to a tcp server. I declared a global TcpClient and NetworkStream and initiate them when the service starts.
Every 30 seconds I go through an array of about 30-40 strings to send to the tcp server.

The send method looks like this:

    private void sendMessage(string message)
    {
            Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
            Globals._stream.Write(data, 0, data.Length);

            if (Globals._responseEnabled)
            {
                data = new Byte[256];
                String responseData = String.Empty;

                Int32 bytes = Globals._stream.Read(data, 0, data.Length);
                responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);

                if (Globals._logStream)
                    Globals._el.writeEventToWindowsLog("Received: " + responseData, "Info");
            }
    }

Problem is that every 30 seconds only a few packets are sent with all of the strings combined inside, I want the strings to be sent in one packet each.

So how do I get the NetworkStream.write method to send the packet immediately? If I declare a new TCPClient and NetworkStream each time I call the send method (about 60times per minute) the data is sent seperately, but thats not a very nice solution. I tried NetworkStream.flush but that wasnt working..

  • 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-12T09:02:43+00:00Added an answer on June 12, 2026 at 9:02 am

    You should set the NoDelay property on the TcpClient to true;

    When NoDelay is false, a TcpClient does not send a packet over the
    network until it has collected a significant amount of outgoing data.
    Because of the amount of overhead in a TCP segment, sending small
    amounts of data is inefficient. However, situations do exist where you
    need to send very small amounts of data or expect immediate responses
    from each packet you send.

    Since you’re wrapping it in a stream, you may still need to flush the stream to send immediately.

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

Sidebar

Related Questions

I need to create some windows service which will execute every some often, every
I have Hudson installed as a windows service on my server. I need to
I need to create some windows service which will execute every N period of
I need to write robust code in .NET to enable a windows service (server
I need to organize windows service which should interacts with applications next way: Application
I need to lock the workstation from a windows service written in VB.Net. I
I need to access to a shared resource with a windows service using local
I have a windows service, written in c# and I need to run a
I need to change thw environment variable Environment.GetEnvironmentVariable(TMP) for a Windows service in .NET
I need a little advice. I've got windows service that runs at night. In

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.