Added function to send object and close the socket connection.