Sign in to follow this  
Tera_Dragon

send splits string up

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this