When either your client or server wish to exit the service loop, one can notify the other by issuing a GOODBYE message.
The format for a GOODBYE message is:
GOODBYE
See Client, Server Disconnect for details describing the client/server disconnect protocol.