better socket class stolen from a blog