Improved connection handling on the server side

Improved connection handling on the server side.