How to know when a socket has finished reading

I know little about sockets, but so far I have not had a big problem. I actually went in cycles on how to find out when the other side finished sending messages. What I still have is a server-side while loop that reads from the socket until nothing remains (or is that what needs to be done). This is the code:

char c[1024]; //buffer
inst much;
while(much = read(sockfd, &c, 1024) > 0) {
   printf("read %d, clientSays> %s\n", much, c);
}
printf("reading, finished\n");

So, on the client side, I send a “hello world” message, which is actually displayed on the server console, but it does not display the message “reading ends”, so I suppose it is stuck waiting for another message,

I’m at least that the read function will return 0 when there is nothing more to read, but I think not in the case of

So what am I doing wrong?


Update

, , , .

, , . , char, , , .

.

+5
2

, read() 0, . , , , , . API , .

+7

, / , char, , .

.

+1

All Articles