1
Network / Strange client outputs...
« on: July 02, 2010, 11:46:19 pm »Quote from: "TheMagician"
It's the c_str() that's appending the null termination:Quotec_str(): Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters.
A terminating null character is automatically appended.
http://www.cplusplus.com/reference/string/string/c_str/
You can use data() to return const char* string without null termination:Quotedata(): Returns a pointer to an array of characters with the same content as the string.
Notice that no terminating null character is appended
http://www.cplusplus.com/reference/string/string/data/
And length() will return size_t length of the string.
So replaceCode: [Select]mainSocket.Send(buffer.c_str(),sizeof(char) * (buffer.size() + 1));
WithCode: [Select]mainSocket.Send(buffer.data(), buffer.length());
At the time I read this, I had already found a solution (a workaround, that is).
I was perfectly sure the terminating null was the problem, and my alternate method of getting in contact with the server showed this.
But I do thank you, Magician. I'm no longer required to use the (quite ugly) workaround.