Serendipitus
November 7th, 2009, 05:50 PM
I have been trying to send a struct through a UDP socket. however i am segfaulting on the recieve side. my struct looks like this
typedef struct myData
{
std::string message;
int seq;
}Data;
i send the struct like so:
sendto(sockfd, (const char*)&mystruct, sizeof(mystruct), 0, (struct sockaddr*)&destSock, c)
and i recive like so:
char buf[MAXRECV];
recvfrom(sockfd, buf, sizeof(Data), 0, (struct sockaddr*)&sourceSock, &c);
(Data) buf;
the sendto and recvfrom calls do not throw an error so something else must be going wrong. i know its generally a bad idea to send structs through sockets but considering im doing this all on one machine it shouldnt matter, correct?
typedef struct myData
{
std::string message;
int seq;
}Data;
i send the struct like so:
sendto(sockfd, (const char*)&mystruct, sizeof(mystruct), 0, (struct sockaddr*)&destSock, c)
and i recive like so:
char buf[MAXRECV];
recvfrom(sockfd, buf, sizeof(Data), 0, (struct sockaddr*)&sourceSock, &c);
(Data) buf;
the sendto and recvfrom calls do not throw an error so something else must be going wrong. i know its generally a bad idea to send structs through sockets but considering im doing this all on one machine it shouldnt matter, correct?