K
kevincw01
I've got this homework assignment where I need to send some data over
a simulated network. Don't worry, I dont want someone to write the
code for me, just wondering if there are problems with the logic of my
solution.
The network API accepts a char* with a maximum of 40 bytes. I can
send and receive char* strings(under 40) all day long without
problem.
Then I created a struct of size 20 bytes:
struct RPCMsgType {
int transaction;
//client side
RPCMsgType rm;
strcpy(rm.name,"testLock");
rm.transaction = 9;
printf("size=%d\n",sizeof(rm));
char *RPCArray = (char*)&rm;
nc.sendMessage(0,0,RPCArray); //network client abstraction that does
a send to the rcvr
If I cast back to the struct on the client side, I have no problems.
However when it's received on server side and I try the same thing, I
get nonsense data:
//network receiver
postOffice->Receive(mbPort, &inPktHdr, &inMailHdr, buffer);
char *buffer = new char[sizeof(RPCMsgType)];
RPCMsgType *rm = (RPCMsgType*)buffer;
printf("Got \"%d\" from %d:%d\n",rm-
This printf always prints some really large number for rm->transaction
when it should be 9.
Obviously there is a big unknown to you, the reader, since there is
this network simulation black box but I'm just wondering if you could
understand why this might be happening, say from personal experience
in a related field? Some of you may recognize the network API and
realize the it is from the NACHOS simulator.
Thanks for any insight, pointers, suggestions, etc...
-Kevin
a simulated network. Don't worry, I dont want someone to write the
code for me, just wondering if there are problems with the logic of my
solution.
The network API accepts a char* with a maximum of 40 bytes. I can
send and receive char* strings(under 40) all day long without
problem.
Then I created a struct of size 20 bytes:
struct RPCMsgType {
int transaction;
//client side
RPCMsgType rm;
strcpy(rm.name,"testLock");
rm.transaction = 9;
printf("size=%d\n",sizeof(rm));
char *RPCArray = (char*)&rm;
nc.sendMessage(0,0,RPCArray); //network client abstraction that does
a send to the rcvr
If I cast back to the struct on the client side, I have no problems.
However when it's received on server side and I try the same thing, I
get nonsense data:
//network receiver
postOffice->Receive(mbPort, &inPktHdr, &inMailHdr, buffer);
char *buffer = new char[sizeof(RPCMsgType)];
RPCMsgType *rm = (RPCMsgType*)buffer;
printf("Got \"%d\" from %d:%d\n",rm-
fflush(stdout);transaction,inPktHdr.from,inMailHdr.from);
This printf always prints some really large number for rm->transaction
when it should be 9.
Obviously there is a big unknown to you, the reader, since there is
this network simulation black box but I'm just wondering if you could
understand why this might be happening, say from personal experience
in a related field? Some of you may recognize the network API and
realize the it is from the NACHOS simulator.
Thanks for any insight, pointers, suggestions, etc...
-Kevin