new socket code, hopefully the last one