I'm rolling my own application protocol on top of TCP. I'm using Linux and C. I'm wondering whether there is an advisable sequence to closing a socket connection.
The client will always initiate the close by sending a specially-formed string; say, "CLOSE". I'd like to receive some kind of acknowledgement from the server that it has seen my CLOSE request, so perhaps it needs to send back a special string like "CLOSE_OK".
I've also seen both the close() and shutdown() system calls, but am not sure how to use them. For instance, should the client, after receiving "CLOSE_OK", do a shutdown(OUTPUT) and then wait to receive a zero-length string? And should the server, after sending "CLOSE_OK", issue close() and then consider the socket to be dead?
I'm hoping there's a "best practice" on this subject that I haven't found yet...