On behalf of akshay@browserstack.com: using keep-alive for remote connection

(minor tweaks to patch made by lukeis)
Fixes Issue #6452