can i use boost::serialization? or what do you recommend? and, how can i send strings between client and the server? thanks
۱۳۹۵-۰۲-۱۰ ۱۱:۲۶ −۰۷:۰۰ گرینویچ, Nathan Pritchard <[email protected]>: > Quite a few things you need to consider, I'll cover (what I think are) > the main two: > > 1) You're not sending the strings for 'username' or 'password', etc. > You're sending pointers. Think about that, you're sending a (in the case > of your 32-bit machine) 4-byte memory address to another client. > > 2) You need to read up Endianness and understand host and network byte > ordering. Bytes ordering for numbers (ints, float, etc) are interpreted > differently by different OSs. > > Consider writing a serialization/deserialization routine for handling > these structs. If you want to be sending dynamically sized structures > with data that needs to be interpreted, you can't just memcpy unfortunately. > > > On 29/04/2016 17:52, Amir Ramezani wrote: >> hello all, >> i want to send struct using eNet, the structure definition is like this: >> //the structure that represents the game data to be sent >> typedef struct gamedata >> { >> const char *username; >> const char *password; >> int rank; >> bool userpass_incorrect; >> bool account_not_exist; >> const char *mac_address; >> const char *hdd_serial; >> const char *ip_address; >> int x; >> int y; >> int z; >> int health; >> bool is_banned; >> bool notify; >> const char *pm_user; >> const char *chat_user; >> const char *message; >> const char *server_message; >> const char *motd; >> bool came_online; >> bool went_offline; >> }gamedata; >> >> now, when my server receive's this struct from client, it crashe's >> size is the size of packet that had been received, and data is the >> packet content variable >> and gd is the structure that i want to process >> i use memcpy to copy from data to struct: >> memcpy(gd, data+size, sizeof(*data) +size); >> but when i receive it, and want to process it, (dirring the >> debugging), i just get a memory access problem >> what am i doing wrong? >> compiler: gcc 5.3.0 >> using gnu++14, >> ide:code::blocks >> debugger: gdb >> operating system: windows7 ultimate 32 bit >> thanks >> _______________________________________________ >> ENet-discuss mailing list >> [email protected] >> http://lists.cubik.org/mailman/listinfo/enet-discuss > > _______________________________________________ > ENet-discuss mailing list > [email protected] > http://lists.cubik.org/mailman/listinfo/enet-discuss > _______________________________________________ ENet-discuss mailing list [email protected] http://lists.cubik.org/mailman/listinfo/enet-discuss
