Iterate over lines in socket properly

The other method was a hack