I don't understand why you need to determine if the socket is "closed" or not.
If you look at this simple example from Q&A
you see that the server never "opens" or "close" a socket but it does create a socket and "accepts" connections from clients and then reads from the socket.
The server detects that client has stopped sending data when the client terminates and its socket is destoryed. For a more complicated client/server system the client could signal the server that it has finished sneding data by sending some sort of flag or by telling the server how much data to expect.
Also for a more than trival server you will need to fork the server after it does the accept because while it
is reading from the socket no other clients will be able to connect. The clients can only connect
when the server is doing an accept. ... I think :)