Boost::Asio - Remove the "null"-character in the end of tcp packets.
Posted
by shump
on Stack Overflow
See other posts from Stack Overflow
or by shump
Published on 2010-06-05T00:51:38Z
Indexed on
2010/06/05
9:12 UTC
Read the original article
Hit count: 255
I'm trying to make a simple msn client mostly for fun but also for educational purposes. And I started to try some tcp package sending and receiving using Boost Asio as I want cross-platform support. I have managed to send a "VER"-command and receive it's response.
However after I send the following "CVR"-command, Asio casts an "End of file"-error. After some further researching I found by packet sniffing that my tcp packets to the messenger server got an extra "null"-character (Ascii code: 00) at the end of the message. This means that my VER-command gets an extra character in the end which I don't think the messenger server like and therefore shuts down the connection when I try to read the CVR response.
This is how my package looks when sniffing it, (it's Payload):
(Hex:) 56 45 52 20 31 20 4d 53 4e 50 31 35 20 43 56 52 30 0a 0a 00
(Char:) VER 1 MSNP15 CVR 0...
and this is how Adium(chat client for OS X)'s package looks:
(Hex:) 56 45 52 20 31 20 4d 53 4e 50 31 35 20 43 56 52 30 0d 0a
(Char:) VER 1 MSNP15 CVR 0..
So my question is if there is any way to remove the null-character in the end of each package, of if I've misunderstood something and used Asio in a wrong way. My write function (slightly edited) looks lite this:
int sendVERMessage() {
boost::system::error_code ignored_error;
char sendBuf[] = "VER 1 MSNP15 CVR0\r\n";
boost::asio::write(socket, boost::asio::buffer(sendBuf),
boost::asio::transfer_all(), ignored_error);
if(ignored_error) {
cout << "Failed to send to host!" << endl;
return 1;
}
cout << "VER message sent!" << endl;
return 0;
}
And here's the main documentation on the msn protocol I'm using.
Hope I've been clear enough.
© Stack Overflow or respective owner