close connection after all messages were sent