in reply to Persistent HTTP connection
Web servers often close connections for various reasons, so your client application has to be prepared to open a new connection as needed, probably also retrying commands. Retrying commands can be tricky if they don't always get a response. Perhaps part of the problem is sending too many non-response commands consecutively.