Better socket opening code