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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:14:13+00:00 2026-06-04T01:14:13+00:00

Not sure if this is the TCPClient or something else, I have used a

  • 0

Not sure if this is the TCPClient or something else, I have used a network sniffer to check what is being sent and received from the server and the data is correct however my software is receiving the data incorrectly.

Let me explain, I transmit an enquiry byte (05) I get a acknowledgment back (06) then I transmit some data that starts with a 9B byte, once this has sent I should then receive a single 06 byte and then after that byte I should get a C5 byte, however according to my software I get another 06 byte which isn’t the case according to the sniffer!

byte[] buff;
if (!this.isConnected())
    this.connect(); 

NetworkStream gs = _Socket.GetStream();

gs.Write(enq, 0, enq.Length);
gs.Flush();
outputByte(enq, "Trans"); //outputs ---> 05

buff = new byte[1];
gs.Read(buff, 0, buff.Length);
gs.Flush();
outputByte(buff, "Rec");// outputs <--- 06

if (buff[0] == 0x06)
{
    byte[] data = new byte[] {
                                            0x9B, 0x00,         0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x09,         
        0x67, 0x11, 0x01, 0x49, 0x4D, 0x41, 0x47, 0x45,         0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         0x01, 0x53, 0x75, 0x6D, 0x6D, 0x61, 0x72, 0x79,         
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,         0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x08, 0x00,         
        0x00, 0x00, 0x1F, 0x09, 0x01, 0x00, 0x04, 0x0A,         0x10, 0x00, 0x12, 0x01, 0x1F, 0x00, 0x00, 0x00,         
        0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,         0x12, 0x10, 0x1E, 0x0E, 0x1E, 0x54, 0x65, 0x73,         
        0x74, 0x69, 0x6E, 0x67, 0x10, 0x00, 0x12, 0x01,         0x1F, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00,         
        0x00, 0x00, 0x00, 0x00, 0x12, 0x10, 0x0D, 0x00,         0x00, 0x90
    };
    outputByte(data, "Trans"); /outputs --> with above byte information
    gs.Write(data, 0, data.Length);
    gs.Flush();

    buff = new byte[1];
    gs.Read(buff, 0, buff.Length);
    gs.Flush();
    // this is the first receive of 06
    outputByte(buff, "Rec");//outputs <--- 06

    if (buff[0] == 0x06)
    {
        gs.Flush();
        Console.WriteLine("fdsfsdfs");
        byte[] resp = new byte[5];
        gs.Read(resp, 0, resp.Length);
        gs.Flush();
        //this outputs <--- 06 but it should be showing <--- c5000100c4
        outputByte(buff, "Rec"); 
        gs.Write(ack, 0, ack.Length);
        outputByte(ack, "Trans");
        gs.Flush();
    }
}

According to the sniffer this is what should be happening

---> 05
<--- 06
---> 9b008000000080000009671101494d414745310000000000000000000000000000000153756d6d617279000000000000000000000000000000000000000000000000000002080000080000001f090100040a100012011f000000050001000000000012101e0e1e54657374696e67100012011f000000050001000000000012100d000090
<--- 06
<--- c5000100c4

And according to the software this is what is happening

---> 05
<--- 06
---> 9b008000000080000009671101494d414745310000000000000000000000000000000153756d6d617279000000000000000000000000000000000000000000000000000002080000080000001f090100040a100012011f000000050001000000000012101e0e1e54657374696e67100012011f000000050001000000000012100d000090
<--- 06
<--- 06

Any ideas? Also if you have any suggestions on how to improve the code I’ll be grateful

  • 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-04T01:14:15+00:00Added an answer on June 4, 2026 at 1:14 am

    Here: you are outputting the wrong buffer:

        gs.Read(resp, 0, resp.Length);
        gs.Flush();
    
        outputByte(buff, "Rec");  <==== should be "resp"
    

    HOWEVER!!!

    all of your Read calls are broken; they MUST handle the return value, especially when reading multiple bytes. Packet fragmentation will kill your code.

    A correct “read exactly [n] bytes” method would be:

    public static void ReadExact(this Stream stream, byte[] buffer,
               int offset, int count) {
        int read;
        while(count > 0 && (read = stream.Read(buffer, offset, count)) > 0) {
            count -= read;
            offset += read;
        }
        if(count != 0) throw new EndOfStreamException();
    }
    

    Then:

    gs.ReadExact(resp, 0, resp.Length);
    

    will fill it correctly, or error if not enough data is in the stream.

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

Sidebar

Related Questions

I'm not sure this is possible, but is there a syntax to be used
Context I'm trying to have some "plugins" (I'm not sure this is the correct
I am not sure this is possible. I have a bunch of @Helper 's
I'm not sure this is a Prototype specific issue, but since I don't have
I'm not sure this is the right place but here I go: I have
Im not sure if i have explaned this the best i can but, here
Not sure this is possible but maybe you can help. I have a list,
I am not sure this is really bubbling, I will explain. I have this:
i downloaded hackbook from https://github.com/facebook/facebook-ios-sdk/tree/master/sample/Hackbook (* i am not sure this is the right
Not sure this is possible, but looking to write a script that would return

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.