need to flush the socket before closing it