implementing socket logic