I am a noob to C++. I have a question regarding initialization of a character buffer dynamically
class Pkg {
public:
Header t;
char buf[LENGTH];
};
I am going to send the object of the class over the network. Header class is converted to network byte order
So, I want to send it like this
Pkg ackpkt;
sendto(sd, &ackpkt, sizeof(ackpkt), 0,(struct sockaddr*)socket1,sizeof(struct sockaddr_in);
The LENGTH field here should be dynamically assigned each time just before I call sendto. One way I think of doing this is by declaring LENGTH to be global.
At the receivers side, I want to receive the object in an object of the same class.i.e the data of object t should be organized in ackpktrecv.t and buffer in ackpktrecv.buf
recvfrom(sd, &ackpktrecv, sizeof ackpktrecv, 0, (struct sockaddr*)&sockaddrs, &len);
How can I receive the object with the character buffer having the same length as LENGTH Can anybody suggest me in what way I can achieve this ?