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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:23:41+00:00 2026-06-05T07:23:41+00:00

I am writing a program in C++ that is sending 1500 bytes of data

  • 0

I am writing a program in C++ that is sending 1500 bytes of data from machine A to machine B.

Assume the following:

char* tx_data = (char*)operator new(1500)
for (int i = 0; i < 1500; i++) {
  tx_data[i] = (char)((int) 65); // ASCII 65 = A;
}
send_tx_data();

So we have the letter ‘A’ 1500 times to fill this buffer (tx_data). The receiving host grabs incoming data and dumps it into a buffer (rx_data), and grabs the length of the received data (rxLength);

rxLength = recvfrom(sock, rxdata, 1500, 0, NULL, NULL);
           //             ^ the buffer we are putting into

If rxLength == 1500, we have received 1500 bytes of data, but we need to be sure it’s the same 1500 bytes we sent (and not 1500 bytes of data from else where, flying round the network)! Typically when comparing some small amount of user input for example, strncmp() might be used. I’m not suggestion that strncmp() is appropriate here, what I am saying though, is that I don’t think it’s a good idea to have on the receiving end, a buffer that might be called expected_data for example, that contains 1500 x ‘A’ and I loop through and compare the two, like strncmp().

How can I evaluate the 1500 bytes of data received in an efficient manner? [By efficient I mean quickly. This will be happening thousands of times a second, so the code needs to be fairly optimal!]. I had an idea about a checksum of some sort, as we know what we should be receiving, but I’m not sure of a good way to do this. Can anyone suggest a good checksum method? Alternatively, if that is a silly idea, could you explain why and perhaps recommend something else?

  • 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-05T07:23:43+00:00Added an answer on June 5, 2026 at 7:23 am

    After multiple suggesstions of hash functions and CRCs, I used code from this answer to another question, to make a simple hash function.

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

Sidebar

Related Questions

I'm fairly new to Qt. This is my second 'real' program that I'm writing.
I'm writing a basic UNIX program that involves processes sending messages to each other.
I am writing a standalone code for Sending mail from java. In this program
I'm writing an application that communicates by sending bytes to the USB port. I'd
I'm working on an assignment that involves writing a program to process data (calculate
I am writing a C program that will read and write from/to a serial
Im writing a program that should read input via stdin, so I have the
I'm writing a program that handles DBs and writes any changes into ListView for
I'm writing a program that's parsing an XML file to java objects using smooks.
I'm writing a program that reads huge file (3x280 GB) and does a fitting

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.