I have some problem with send data by boost::asio. My code:
void Connection::SendCommand(std::shared_ptr<ICommand> command)
int dataSize = command->GetSize();
vector<char> dataBuffer = vector<char>(dataSize);
if(_side == Server)
int* header = new int;
header = (int)(command->Type());
header = (int)FromClientToServer;
header = dataSize;
size_t s = _socket->write_some(buffer(header,
size_t s1 = _socket->write_some(buffer(dataBuffer,
I get exception on the second call write_some:
ctor<boost::system::system_error> > at memory location 0x0021F520.
Does anybody know what is wrong?
The only immediate problem I see is the "write_some". From the documentation for "write_some":
"The write_some operation may not transmit all of the data to the peer. Consider using the write function if you need to ensure that all data is written before the blocking operation completes. "
I would use "write" as recommended in the Asio docs (or change to use async operations, or change the logic to use the return value of "write_some").