client: move the "response" and "socket" event handlers out into named functions

Cleaner code == better