I actually tried a client server code using TCP Select. I don’t know why is the garbage value printed after every request from the client is printed on the server
Here is the server code
https://www.dropbox.com/s/qgd87fby6tif9q6/server.c
Here is the client code
https://www.dropbox.com/s/qlv1im06gfw5i1w/client.c
You’re treating the message received on the server as a string but aren’t sending a nul terminator from the client. This leads to old content in
recv_bufand possibly further down the stack being displayed as printf scans memory for the next byte with value 0. You could address this by either sending a nul terminator from the client by changing yousendcall to include the string terminator in your messageor in the server by adding a nul terminator after receiving the message
[Original answer retained below in case you also want to remove the newline from messages. And because that’d have inadvertently fixed your problem.]
“garbage value” doesn’t give us a lot to go on…
At a guess, these characters may be newlines (single character with value 0x0D). From the fgets man page (my emphasis)
fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A terminating null byte (aq\0aq) is stored after the last character in the buffer.
The string your client reads may end in a newline. If you don’t want to send this to the server, you could remove it by adding
to your client, between its calls to
fgetsandsend.