refactoring server socket