J
Jack
Hi, All,
is it possible to send a struct using the the send function. Here is
what I mean
typedef struct{
int ID;
char name[20];
}sampleStruct;
int main(){
sampleStruct a;
//lets assume we have filled out our sin_family and etc. so
we'll have something like:
sd = socket (AF_INET, SOCK_STREAM, 0);
connect (sd, (struct sockaddr*) &socketChannel, sizeof(struct
sockaddr);
a.ID = 1;
a.name="Bob";
send(sd, (void*) a, sizeof(a), 0);
...
...
...
}
Is there anyway to make this work or do I need to make a char buffer
and write
buffer[100] = "1 Bob";
send(sd, (void*) buffer, strlen(buffer), 0);
Thanks
is it possible to send a struct using the the send function. Here is
what I mean
typedef struct{
int ID;
char name[20];
}sampleStruct;
int main(){
sampleStruct a;
//lets assume we have filled out our sin_family and etc. so
we'll have something like:
sd = socket (AF_INET, SOCK_STREAM, 0);
connect (sd, (struct sockaddr*) &socketChannel, sizeof(struct
sockaddr);
a.ID = 1;
a.name="Bob";
send(sd, (void*) a, sizeof(a), 0);
...
...
...
}
Is there anyway to make this work or do I need to make a char buffer
and write
buffer[100] = "1 Bob";
send(sd, (void*) buffer, strlen(buffer), 0);
Thanks