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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:40:16+00:00 2026-06-02T23:40:16+00:00

I’m creating a socket-based telemetry app, I use two radio modems to send/receive data,

  • 0

I’m creating a socket-based telemetry app, I use two radio modems to send/receive data, one app sends data via modem 1 and the other program gets data through modem 2, my send interval is one second, it seems that the receiver app (the server) is using most of CPU and RAM resources (99% cpu usage!) and its memory usage increases steadily! so that after some minutes my program almost stops responding and my data is not correct at all, so data cannot be parsed, it seems that my programs receives several copies of the sent data, my original data packet is about 70 bytes, but after some seconds its size increase, I think my receive buffer is full and data is mixed with previous data, I’m looking for some suggestions, here is my receive handler in server program:

private void DataReceive()
    {
        handler.ReceiveBufferSize = 100;

        try
        {
            byte[] bytes = new byte[100];
            int byteRec;
            while (true)
            {
                timer1.Enabled = true;
                while (true)
                {
                    byteRec = handler.Receive(bytes);
                    if (byteRec > 0)
                    {
                        data = System.Text.Encoding.UTF8.GetString(bytes, 0, byteRec);
                        break;
                    }
                }

                if (data.Length >= 30)
                {
                    if (data.Substring(0, 1) == "#")//pasrse data, correct!
                    {
                        label27.Text = data.Length.ToString();
                        textBox1.Text = data;
                        string a = data.Substring(1);

                        string[] b = a.Split('-');

                        SetControlPropertyThreadSafe(lblTotal, "Text", b[0]);
                        SetControlPropertyThreadSafe(lblFlow, "Text", b[1]);

                        float real_analog2 = (1 - (((20 - float.Parse(b[4])) / (20 - 4)))) * Analog2_Max;
                        if (real_analog2 < 0)
                            real_analog2 = 0;
                        SetControlPropertyThreadSafe(lblAnalog, "Text", real_analog2.ToString());

                        if (b[2] == "1")//off
                            SetControlPropertyThreadSafe(lblMotion, "Text", "off");
                        else if (b[2] == "0")//on
                            SetControlPropertyThreadSafe(lblMotion, "Text", "on");

                        if (b[3] == "1")//off
                            SetControlPropertyThreadSafe(lblMotion2, "Text", "off");
                        else if (b[3] == "0")//on
                            SetControlPropertyThreadSafe(lblMotion2, "Text", "on");

                        SetControlPropertyThreadSafe(lblV1, "Text", b[5]);
                        SetControlPropertyThreadSafe(lblV2, "Text", b[6]);
                        SetControlPropertyThreadSafe(lblV3, "Text", b[7]);
                        SetControlPropertyThreadSafe(lblI1, "Text", b[8]);
                        SetControlPropertyThreadSafe(lblI2, "Text", b[9]);
                        SetControlPropertyThreadSafe(lblI3, "Text", b[10]);
                        SetControlPropertyThreadSafe(lblLevelPercent, "Text", b[11]);
                        SetControlPropertyThreadSafe(lblLevelValue, "Text", b[12]);
                    }
                }
                FillLstMsg(data);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
  • 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-02T23:40:17+00:00Added an answer on June 2, 2026 at 11:40 pm

    Basically I think that your approach is wrong.

    How can you say the data size sent-received?
    When is the first packet-message ends and another one starts?
    Do you know how big is your full packet message is?

    These are some issues you should carefully validate while receiving packets from the other end.

    A common practise I have inherited on my TCP implementation is first send packet size that is coming and then handle the message based on that packet size. This will give you great flexibillity creating a more robust TCP implementation. If you do this you can then send as many packets as you want one after another without crashes.

    I also see that you messed up presentation code with receiving data code.
    You should create a seperate class library to handle all your TCP communication operations,
    and throw the received data in the consumer application.

    Nito Async library was a very good starting point for me. You could see what he is doing, though is too advanced techniques and real good code in there, you can catch the basic idea.

    Start from this beautiful explanation in his blog and then catch the code in codeplex. I see now that he updated some stuff, so you can get all his effort to your code, or even his if it suits to you 🙂

    http://nitoprograms.blogspot.com/2009/04/tcpip-net-sockets-faq.html

    Happy reading!

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.