I am writting the socket with C++ under Linux. I have a question. How I can find out whether the client closed the connection.
Especially in the situation in which the server accepted the client and started to wait for some data from client. But the client does not send anything and just closes the connection to server. In this situation my server is waiting forever for some data.
Here is example of my program:
newsockfd = accept(sockfd,
(struct sockaddr *) &cli_addr,
&clilen);
if (newsockfd < 0)
error("ERROR on accept");
bzero(buffer,256);
n = read(newsockfd,buffer,255);
Also I have several sockets on my server. I need to know to which socket the client closed the connection.
If the client closed the connection,
n = read(newsocketfd, buffer, 255)will return 0.