我想将断开连接类型的断开数据包作为一个字节发送。 我做了结构等等。
struct NET_PROTO_HEADER
{
unsigned int mLength;
unsigned short mPacketGroup;
unsigned short mPacketType;
};
struct NET3_SERVER_DISCONNECT : public NET_PROTO_HEADER
{
unsigned char mType;
};
但是当我尝试发送它时,sizeof方法返回大小为12,并且它在末尾以addonitional nulls发送。
NET3_SERVER_DISCONNECT data;
data.mLength = 9;
data.mPacketGroup = 3;
data.mPacketType = 100;
data.mType = 0xcb;
boost::asio::async_write(socket_, boost::asio::buffer((char*)&data, sizeof(data)),
boost::bind(&Connection::handle_write, shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
我在这里做错了什么? 感谢。