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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:15:32+00:00 2026-05-30T04:15:32+00:00

I am just starting out with network programming and I am having trouble keeping

  • 0

I am just starting out with network programming and I am having trouble keeping up with some of the stuff. Namely because there is a lot of auto-magic stuff going on under the hood that is hidden away from me, and I cant get my head around it all. In my current app, I take user input like so:

char buff[1024];
cout << "Enter a message:";
fgets(buff, 1024, stdin);

And i can easily send that off by essentially doing this:

sendto(m_socket, buff, size, flags, (SOCKADDR*)&addr, sizeof(addr));

The other variables (size,flags,etc) are obviously initialized and configured somewhere between the input and sendto call.

This all works fine, and the other end receives the data fine. the server does

recvfrom(m_socket, (char*)data, max, flags, (SOCKADDR*)&fromAddr, &fromLength) 

and I can then just print out ‘data’ into the console, and it’d be my message.

So where exactly is my UDP packets header? Did i have to specify it? when i pass in some data, is the ‘data’ part of a standard UDP packet filled with the data i specify, and the header automatically populated for me (source IP, destination IP)? If so how do i even access it?

A lot of websites I have looked at talk about headers and what not. It seems to be this very specific thing. But I dont understand how this illusive header works.. I’d like to define my own header with things like segment number, total segments, etc. but i dont know how to go about this at all. My googleing isnt sending me in the right direction either..!

  • 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-30T04:15:34+00:00Added an answer on May 30, 2026 at 4:15 am

    UDP does not contain such things as headers, segment numbers and total segments. In fact, a UDP datagram contains nothing except the buffer that you sendto.

    You can add extra information by including them with your message. Instead of simply putting your message in your buffer, make a larger buffer into which you put whatever “header” information you would like and then put your message afterwards.

    From UDP’s perspective, all it sees is data. It is up to the program on the receiving end to parse this data and realize that a certain part it is metadata and the other part of it is regular data.

    You will have to define your message format such that it is easy for the receiving program to extract the “header” portion of the buffer. There are two common schemes: fixed headers and variable length headers.

    If you are going for a fixed header, you assume that the first X bytes of every UDP message are metadata. You pick the X and it never changes per message. The recipient then knows to read X bytes as the header and all the rest as a message.

    If you are going for a variable length header, you need to be able to tell the receiving end how long the header is for each particular message. A common scheme is that the first 4 bytes of the header contain an integer which says how long the header part of the message is. Then the receiving end reads that many bytes and interprets that as the header. Then it reads the rest of the data and interprets that as the message.

    Lastly, the source IP and the destination IP are not properties of your UDP messages but rather properties of your socket. You can retrieve this information by inspecting the socket itself.

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

Sidebar

Related Questions

I am just starting out with RoR, and I'm having some problems. I'm using
I'm just starting out with the whole ajax thing and I need some help.
Just starting out to program in python and I'm having the following issue. I
Only just starting out with jQuery and I'm sure this is basic stuff for
I just starting out in C++ and I've reached a problem in some practice
I'm just starting out with node.js, express and ejs. And I'm having a hard
Hey - just starting out trying to get some openGL into my iphone app
I'm just starting out with iphone development and ran across some example code that
I'm just starting out with WCF web services, and I'm having a really hard
I'm just starting out with WPF and need some help with routed events. I

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.