When I read from a SOCK_STREAM socket like this:
int t;
while ((t = read(clientsocket, buff, 128) > 0))
{
write(1, buff, t);
}
read always return 1, but if I look into buff with gdb I can see the whole line I sent. I'm using netcat to send data to the server.
This is incorrect due to operator precedence:
while ((t = read(clientsocket, buff, 128) > 0))
and results in t being assigned the result of read(clientsocket, buff, 128) > 0, which will be 0 or 1.
To correct, change to:
while ((t = read(clientsocket, buff, 128)) > 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With