improved socket handling in webserver