extract socket related functions to separate module