hey all. i tried to write a binary object to a file and then read it out and it worked fine. But when i try to use sockets in order to send the object over a socket its failing giving nothing in return. i'm using the localhost so the client/server are on the same environment.
The packet class is as follows:
1 2 3 4 5 6 7 8 9 10
class PlayerLocation
{
public:
char pName[8];
char actionType[10];
int x;
int y;
int z;
int mapID;
};
Ya i know that. I only wrote the send and recv function to explain how am i doing it and I did send the data as text before and worked successfully. but when sending it binary its not received.
If it still doesn't work, try to send the file where you store the object first.
After that try to reconstruct the object on the receiving side.
By the way, the correct way to send or store objects is serialization/unserialization.
The approach of direct memory reading is possible but works for simple objects only.
Oh, okay, then.
Don't send the binary contents of a class over a network. If you need to do something like this, first serialize the contents and then send them. Your method breaks very easily.
tnx for the reply the old problem was solved, it was nothing found in the code above but a different thing. my problem is serialization now, i posted another post concerning serialization where i have an std:string in a class that needs to be converted to binary in order to send it or save it to hd. so is there a free easy to use serialization library i can use?