It will send "hello" + 1 byte which will be a garbage char because send() doesnt put '\0' at the end either.
Nope. "hello" is a length 6 character array, containing
Code:
{'h', 'e', 'l', 'l', 'o', '\0'}
strlen("hello") returns 5, of course. Thus:
Code:
send(s, "hello", 5, 0); // or strlen("hello")
Sends 5 characters: h, e, l, l, o.
Code:
send(s, "hello", 6, 0); // or strlen("hello") + 1
Sends 6 characters: h, e, l, l, o, \0. No garbage.
Now, you need some sort of serialization of data between the two. Unless you only plan on sending on string, you'll need something to break up the strings. A null terminator, or a length prefix. The recv()ing side will have to buffer the data appropriately.
send() is a very simple function. It sends a buffer of so many bytes. Likewise, recv() receives a buffer of so many bytes. Neither function knows anything about strings - that's way out of their scope. It send()s/recv()s data - ie, arrays of bytes. Period. You have to implement the protocol from point A to point B.