Implement socket function
Tweak error handling
Error handling