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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:50:52+00:00 2026-05-26T18:50:52+00:00

My program uses UDP to send data between two programs, it works great however

  • 0

My program uses UDP to send data between two programs, it works great however I have added a new vector into the data I want to send, the vector type is another class which looks like this…

class Bullet: public Sprite
{
public:
    float speed;
};

The DataPacket…

typedef struct DataPacket
{
    int ID;                             //Player ID
    int elapsedTime;                    //Total elapsed player time
    float x, y;                         //X & Y pos of player
    std::vector<Bullet>* pBullets;      //Vector containing all the players bullets
};

Is there a way to send this data correctly? The expression cannot be evaluated once the server receives the data from the client, every other part is correct in the received packet.

Basically the server is receiving the positional data of the bullets on the screen which is contained in this Bullet class along with a few other items.

Just to note: pBullet never used to be a pointer but in an attempt to try and figure out what was wrong I changed it to a pointer…it never fixed the issue tho

  • 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-26T18:50:53+00:00Added an answer on May 26, 2026 at 6:50 pm

    You cannot do this. A vector is a class which is typically implemented with an internal pointer to dynamic memory which changes location as the vector grows.

    When you try and serialize the vector by casting your whole structure, you just serialize the pointer to the memory holding the vector contents, you don’t get the contents itself because it’s not part of that structure.

    You’ll have to individually serialize all items in the vector one-by-one and individually add them back in when you deserialize it.

    Note that you can change the vector of bullets to a statically sized array internal to the structure and then it would be contiguous in memory and you could just serialize the whole structure – and you can also make the last element of the array an array of one bullet, and then allocate memory for the structure size + (x-1)*sizeof(Bullet), allowing you to overwrite the array of 1 for all of the extra memory you added. This would also be contiguous in memory allowing you to serialize the whole memory region pretty easily.

    You should also look in to htonl, ntohl, htons, ntohs and start network-byte-ordering your data as well if you’re going to send it over a network to keep the byte endianness from being an issue on some other systems you might end up using.

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

Sidebar

Related Questions

I've written two programs. Now each program uses threading to send and receive packets
I have a program that defines a variable int data The program uses scanf(%d,&data)
I have a linux applications which sends data over UDP protocol. It uses these
My program uses some external programs that i included in the Files folder. In
My program uses sqlite3 plus python. It works fine with python 2.6.2 I moved
I have a program that uses the mt19937 random number generator from boost::random. I
My program uses a NetworkOutput object which can be used to write data to
I have a Python program uses Qt (PyQt4 in fact) and when I launch
There are two large text files (Millions of lines) that my program uses. These
I have a simple C# application that uses UDP multicast in a single-receiver, single-sender

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.