Another Problem :) But i am certainily learning and i really appreciate all the help I have received so far! Ok in my game I am now trying to send structs across via Winsock, instead of simple Char's. After looking at the FAQ, I got the server to send one correctly. And the client receives it, however, I am doing something wrong (I think client side after casting the retaining struct as a (char*) As when I go to pull out data, what was 20 before being sent, is pulled out as 0 on the client. I am assuming the stuct on the client is completely empty. Here is code sending struct on server:
bool MessageHandler::SendPlayer(playerType message)
{
int nret = send(client,"Pstruct done#",14,0); // used to tell client a structure is coming
Sleep(500);
nret = send(client,(char const*)&message,sizeof(message),0); //sending a playerType struct to client
if (nret == SOCKET_ERROR || nret == 0)
{
Sleep (2000);
int nret = send(client,(char const*)&message,sizeof(message),0);
if (nret == SOCKET_ERROR || nret == 0)
{
WriteError("failed to send message");
return false;
}
}
else
{
}
return true;
}
playerType is the struct I am trying to send across. Sending the Pstruct first allow my client to know a players structure is coming next, and to go to the function to receive it. Clients Recieve code:
void netReceiveStruct()
{
int ret = recv(st, (char*)&Player, sizeof(Player), 0);
if (ret <= 0)
return;
receivePlayerStruct = false;
WriteError("struct received");
//sake of testing
char testC[10];
itoa(Player.moves,testC,10);
WriteError(testC);
//
}
Player is also a playerType struct, and is declared as a global. Writing out v alue before being sent moves = 20. When it writes it out after receiving it is 0. Any suggestions?
[Edited by - TalonSnow on May 1, 2005 10:03:25 PM]