Change send_all to avoid getting stuck in infinate loop.

- Add raising an exception in while loop when connection is lost to prevent
getting stuck there when connection is lost.
- Add small delay (100 ms, i.e. a little longer than ping) before while
loop to reduce log spam and delay in sending messages.