Add socket event handlers.