Remove case 6 from rmt:send-receive. This was pinging the server constantly and opening addtional connections that don't appear to being closed. Also, just let the connection die, it should retry.