Welcome! Log In Create A New Profile

Advanced

Struct Int Problem?

Posted by CrystalSpark 
Struct Int Problem?
October 22, 2010 09:23PM
Hi there.

So I'm trying to create an application for Wii that communicates with my PC.
The problem I've got is `char` works, but when I use `int` it doesn't work properly. The `int` either displays a number that is totally off, or it just renders the screen to nothing. I made a PC client, and it works fine its just the Wii isn't working properly????

I've got something like for this for both Wii (client) and PC (server) its just a snipplet:

Quote

struct info{
int x;
char a;
};

PC side:
Quote

void main() {
info rdata;
rdata.x = 17;
rdata.a = 'A';

int len = sizeof(rdata);
n = send(newsockfd, &rdata, len, 0);
}

Wii side:
Quote

struct info recv;
int recvlength;
net_read(connection, &recvlength, 4);
GRRLIB_Printf(255, 115, tex_BMfont5, GRRLIB_LIME, 1, "recvlen: %d",recvlength);

net_recv(connection,&recv,recvlength,0);
GRRLIB_Printf(255, 125, tex_BMfont5, GRRLIB_LIME, 1, "x: %d", recv.x);
GRRLIB_Printf(255, 155, tex_BMfont5, GRRLIB_LIME, 1, "a: %c", recv.a);
Re: Struct Int Problem?
October 22, 2010 09:27PM
Your PC is little endian, the Wii is big endian so you need to make sure that any values you send are either converted or make your data transfer endian agnostic. Conveniently network traffic is designated big endian so there are standard functions provided to convert between host and network byte ordering. See [linux.die.net] for a list of these functions.

PC Side:
Quote

void main() {
info rdata;
rdata.x = htonl(17);
rdata.a = 'A';

int len = sizeof(rdata);
n = send(newsockfd, &rdata, len, 0);
}

Wii Side:
Quote

GRRLIB_Printf(255, 125, tex_BMfont5, GRRLIB_LIME, 1, "x: %d", ntohl(recv.x));
Sorry, only registered users may post in this forum.

Click here to login