while (((connfd = accept(listenfd)) != -1){
if (fork() == 0) {
write(connfd, buffer ,strlen(buffer));
close(connfd);
}
}
Hi all, I got a sample question for an exam at OS. Let's say I have a TCP server which handles multiple clients, using the above code. As specified in the question, the rest of the code should be valid. Now, each time a client connects to this server, it reads data from it and then gets stuck. The correct answer to the question is that it happens because the server doesn't close the connection with the client properly.
I'm not sure if I get it completely, isn't
close(socket)
enough? As far as I'm concerned, when a socket is closed by one side, the other side reads EOF and returns 0. Considering the client gets stuck while reading, it shouldn't get to that EOF and move on?