fixed segfault (was resetting socket to -1 with ==, not =  )