While sending the string
buf, the length of the string has to be strlen(buf) and not sizeof(buf). For reasons take a look at the code below,
Code:
char message[1000];
.....
.....
strcpy(message,"hi");
send(sockfd,message,strlen(message)+1,0); // sends 3 bytes
send(sockfd,message,sizeof(message),0); // sends 1000 bytes
If you use sizeof(message) then 1000 bytes will be sent which is unnecessary because only 3 bytes are meaning full.