move socket process out of main func