socket将结构体转换为字符串 传输问题

socket通信像结构体中嵌套结构体时,收到的数据错误,谁遇到过?求大神们指导

传输的结构如下:
struct CatchFish {
int fish_id;
int fish_kind;
SCORE fish_score;
bool bullet_double;
int link_fish_id;
bool bullet_invincible;
bool sepcial_sence;
int special_fish_kind_;
DWORD special_start_fish_id;
};

struct CMD_S_CatchFishGroup {
DWORD tick_count;
WORD chair_id;
int fish_count;
CatchFish catch_fish[kMaxCatchFishCount_FishLK2];
int bullet_id;
};
像这样的数据,在catch_fish的第一个数据fish_id是对的,其他的大部分是错误的?这是什么原因造成的?

先看你收到的数据是否正确,然后就是你截取,读取缓冲区数据的时候,对应的类型等是否映射对。

什么叫结构体转换为字符串?结构体的数据是二进制的,转换为字符串数据会被破坏,必须以二进制数组的方式传输。如果目标计算机使用的编译器/机器架构不同,还要注意对齐和字节序的问题。