close socket after sending all messages