Socket reading function