separated socket logic into separate file