Hello All,
I am having trouble using boost:asio
to send a simple struct message_header from server (linux) to the client
(windows).
typedef struct MessageHeader
{
uint32_t
_data_length; //length of data attached
uint8_t
_message_type; //MESSAGE_TYPE
uint8_t
_segment_name; //SEGMENT_NAME
uint16_t
_request_id; //Request Id assigned by
the client to the request to uniquely identify the request
uint16_t
_count_of_records; //Number of records affected by the operation,
0 means complete segment is affected.
} MessageHeader;
typedef struct Message
{
boost::array<char,
header_length> _header_array;
} Message
Server side code (Linux):
===============
MessageHeader
request_header;
request_header._data_length
= 0;
request_header._message_type
= MSG_READ;
request_header._segment_name
= SEG_OOW;
request_header._count_of_records
= 0;
request_header._request_id
= 100;
string _data_serialized
= "";
uint8_t header[header_length];
//header_length is defined as 10
memcpy(header,
(uint8_t*)(&(request_header)), header_length);
std::vector<boost::asio::const_buffer>
buffers;
buffers.push_back(boost::asio::buffer(header,
header_length));
buffers.push_back(boost::asio::buffer((_data_serialized).c_str(),
_data_serialized.length()));
boost::asio::async_write(_socket,
buffers, boost::bind(&ClientSession::handle_write, shared_from_this(),
boost::asio::placeholders::error));
Client Side code (Windows):
================
Message
_read_message;
MessageHeader
_message_header;
Handle_connect(....)
{
boost::asio::async_read(_socket,
boost::asio::buffer(_read_msg._header_array, header_length), boost::bind(&DJClient::Handle_read_header,
this,
boost::asio::placeholders::error));
}
Handle_read_header(...)
{
memcpy(&_message_header,
read_msg._header_array.data(), header_length);
}
Surprisingly the same code works fine
from "Windows to Windows" and "Windows to linux" but
has problem when used on "Linux to Windows". When sent from Linux
server, Windows server receives garbage data. Sending of normal ASCII characters
from Linux to Windows work fine. Please help if anyone can.
Thanks and Regards,
Anil Agrawal