send splits string up

Started by
3 comments, last by antareus 19 years, 7 months ago
When I use send(...) to send data over a network, if the data I sen is in a string, words in a sentence are sent seperatly. This doesn't happen if I use a char buffer. Is there any way that I can stop this happening and continue to use strings?? Tera_Dragon
____________________________________________________________Programmers Resource Central
Advertisement
Aren't you passing send the return value of c_str() on your string? If not, then your code is wrong, and the reason you are seeing truncation is because you're sending private data of the string object as well as the character array.

Keep in mind that send is not guaranteed to send all the data you pass it anyway. That's why it returns the number of bytes sent.
Yes, I am using c_str(), and also casting it as (char*).
____________________________________________________________Programmers Resource Central
Theres no reason why sending data as a char buffer would differ from sending it as a std::string. As far as Winsock is concerned, its still getting a char* and a length. Can we see some source code?
TCP connections are stream-based. There is no guarantee that the buffer you send on one side is what the other side will see in one packet. It may be broken up, or you may have two packets collapsed into one.

Solution: buffer the data and know when it ends, or keep lots of state.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis

This topic is closed to new replies.

Advertisement