Hi, I'm trying to learn the in's and out's of using the send and recv functions of a socket in C and I've hit a bit of a road block!
I'm trying to send an integer from one system to another, however one system is big endian (the client) and the other is little endian (the server). My goal for the moment is simple: I want to type an integer in the client and send it to the server and have the server print it out.
Here's the essentials of what I'm trying now:
client.c
struct myPacket {
int a;
double b;
double c;
int d;
char e[80];
};
int main(){
[...]
struct myPacket msg;
[...]
printf("Enter an integer:");
fflush(stdout);
scanf("%d",&(msg.a));
send(sockfd,(void *)msg.a,sizeof(msg.a),0);
close(sockfd);
return 0;
}
server.c
[...]
int a;
retval = recv(clientfd, &a, 4, 0);
printf("Message: %d\n", ntohl(a));
[...]
And this gives me garbage. For example, entering "1" on the client returns "415170816" on the server. Also, for the record, I was successfully able to get a character array to pass from the client to the server (that's the char e[80]; in the client code). I was hoping to just have to change the data types but no such luck.
Any help is greatly appreciated!
--Dan