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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:40:04+00:00 2026-05-21T22:40:04+00:00

Hi guys i have an issue currently when using a Socket to send data.

  • 0

Hi guys i have an issue currently when using a Socket to send data.

I am currently getting a very strange issue when a Client sends to the server, for example “HEART”, as a heart beat. afer sending the first time the server starts receiving a whole lot of \0, not always the same amount before the HEART. I am using queues to queue up sending so on slow connections it waits for the current send to be done before it sends the next but for tiny lengths like that i’m a bit confused.

    public void Send(string data)
    {
        if (Connected)
        {
            SendQueue.Enqueue(data);
            if (t.ThreadState == ThreadState.Stopped)
            {
                t = new Thread(new ThreadStart(SendData));
                t.Start();
            }
            else if (t.ThreadState == ThreadState.Unstarted)
                t.Start();
        }
    }

and the SendData function

    private void SendData()
    {
        if (sending)
            return;
        sending = true;
        while (SendQueue.Count > 0)
        {
            if (ClientSocket.Connected)
            {
                byte[] data = Networking.StringToByte((string)SendQueue.Dequeue());
                ClientSocket.Send(data);
            }
        }
        sending = false;
    }

i don’t think it’s the sending function because i’ve debugged it and the byte array always holds the correct info.

the receiving end is even simpler.

    public string Receive()
    {
        string msg = "";
        if (Connected)
        {
            byte[] data = new byte[1024];
            while (ClientSocket.Avaliable > 0)
            {
                ClientSocket.Receive(data);
                msg += Networking.ByteToString(data).Trim();
            }
        }
        return msg;
    }

If anyone could point out where i’m going wrong or if i’ve gone at this the entirely wrong way that would be great.
Thanks guys.

I will remind people that it’s seemingly random lengths of \0 each 2 seconds (in this example for the HEART message heartbeat)

  • 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-21T22:40:05+00:00Added an answer on May 21, 2026 at 10:40 pm

    This piece of code can’t be correct:

        byte[] data = new byte[1024];
        while (ClientSocket.Avaliable > 0)
        {
            ClientSocket.Receive(data);
            msg += Networking.ByteToString(data).Trim();
        }
    

    It seems you do not take into account how much data you actually receive. You have to look at the return value from ClientSocket.Receive I don’t know what your Networking.ByteToString does but when your code runs Networking.ByteToString , that function cannot know how much data you actually received. It’ll probably convert the entire buffer – all 1024 bytes. And that’s likely where all your zeroes comes from. It could be that somewhere you’re doing a similar thing on the sending side.

    You also might need to keep in mind that TCP is stream oriented, not packet oriented. If you do 1 Send call, that can take several Receive calls to read, or 1 Receive call might read the data from many Send calls.

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

Sidebar

Related Questions

Hey guys another rails issue, Currently have a collection that is line items for
Hi guys I have a strange issue. I am trying to get list of
When reading about SQL Injection and XSS i was wondering if you guys have
How have you guys handled working with jQuery includes <script type=text/javascript src=jquery.js></script> in Asp.Net
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you guys and gals got any tips or hacks for making the most
Ok guys just a small game: I have some specifications for a project. At
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
I have heard several podcasters (most recently the guys on DotNetRocks ) say that
Problem solved: Thanks guys, see my answer below. I have a website running 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.