Improved connection handling on the server side 2

Improved connection handling on the server side 2.