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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:48:43+00:00 2026-06-03T07:48:43+00:00

I tried searching everywhere but no luck. Here is my problem: I have a

  • 0

I tried searching everywhere but no luck. Here is my problem:

I have a UDP socket, which can send data to any IP address through any port (tested and confirmed working).

I read many tutorials, but they were all manipulating char*[], they did not specify how to decrypt it.

What I would like to do (pseudo code):

Client:

Class my_class;
send (..., my_class, sizeof(my_class),...)

Server:

receive (sender, buffer, sizeof (buffer))
and do something like
Class my_class = (Class) buffer

So I my server can analyze the content of the buffer.

But I’m lost with pointers, and all I can send is char*[], so I don’t know how to convert back and forth.

  • 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-03T07:48:44+00:00Added an answer on June 3, 2026 at 7:48 am

    You can’t just “send” your class. You have to send a representation of the data in your class. And sending a pointer to your class won’t work either. When another application on the network receives your pointer, it will be meaningless to them.

    Consider this:

    class Data
    {
      std::string  name_;
      unsigned value_;
    } data;
    

    You can’t just “send the class” down the wire. If you tried to do something like this:

    send(&data, sizeof(data));
    

    …you will end up sending nonsense to the downstream client. value_ might be received properly, but name_ surely won’t. This is because a std::string object consists of much more than just the characters that make up the string. There are also counters, pointers to data buffers, and who knows what else. The characters themselves are probably not even going to be in the memory space indicated by (&data, &data[sizeof(data)]) — those characters will be somewhere else entirely. So with the send psudocude above, not only do you send a bunch of stuff that the client can’t understand, very often you don’t even send what they can understand.

    Enter serialization. Serialization simply means creating a representation of your data object that can be stored, saved or sent someplace, and reassembled later. You decide what shape this serialization will take. In the case of data above, we might decide to serialize like this:

    NNNNCCCCCCCC...VVVV
    

    where each character is 1 byte, and:

    1. N is a 4 character integer, and is the number of characters in name_ in ASCII representation
    2. C is N bytes, with each one being one character in name_
    3. V is a 4 character unsigned integer, and is the value in value_ in ASCII representation

    One way to serialize & send data above might be something like this (warning: not production quality, untested):

    stringstream ss;
    ss 
      << setw(4) << setfill('0') << right << data.name_.length() << setw(0)
      << data.name_
      << setw(4) << data.value_;
    
      string buf = ss.str();
    
      send(buf.c_str(), buf.length());
    

    Now, instead of trying to send data, we’re sending a character string that represents data. If data was created like this:

    data.name_ = "foo";
    data.value_ = 42;
    

    …then the string that gets sent down the socket will be:

    0003foo0042
    

    This can be received by the client and reassembled in to a new Data object on the client side that mimics what you have on the server side.

    The mapping we used above — the NNNNCCCCCCCC...VVVV — must be understood by both sides. This is often referred to as a communications protocol.

    There are countless protocols and serialization methods used across all application domains. They range from the uber simplistic, like the one I outlined above, to highly compressed and complex, like FIX/FAST. Many libraries provide serialization capabilities that meet the needs of a wide range of applications. Boost.Serialization comes to mind, and I’d suggest you look in to that.

    There is much more to this that I’ve glossed over here. Things like Endianness, security, session control… If you are going to be doing any significant network programming, either on the client side or the server side, you’ve got quite a bit of learning ahead of you.

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

Sidebar

Related Questions

I have a problem here. I've tried searching everywhere but can't seems to find
I have tried searching over the internet about this problem but not able to
How to anti-alias a collada model in papervision3D? I've tried searching everywhere but didn't
Tried searching the site, but cannot find an answer to my problem: Lets say
I tried searching for this but couldn't find a similar question. I have a
I tried searching here , but it couldn't help me much .. I want
I tried searching in google but could not find any useful answer, if(verifier.length() >
I tried searching and didn't find anything that fixed my problem. I have a
I tried searching for this but I have not found anything. If I have
I've tried searching on this but can't seem to find an answer anywhere, so

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.