I have the following structure defined in C, and I want to send it using Berkeley Socket over a TCP connection between client and a server in Linux:
struct Argument{
int pid;
int length;
chat op;
char *data;
};
Since I have "char *data" which is a pointer than can be used for allocating a variable size of data in the local sending machine, I have to send this structure in two different times to the receiver side. The first time, I send only the fixed variables i.e. the first three variables. And then upon the reception, I allocate a buffer with a length size to receive the data part in the second time.
So my question is is there anyway to only send this structure one time to the other side with a variable data field size, not two times as what am I doing?
if (write(peer_fd, (struct Argument*) arg, sizeof (struct Argument)) < 0)
{
close(peer_fd);
return -1;
}
Thanks a lot.