Change socket.io for sockjs, and some network event refactoring

This is a work in progress, so there could be improvement later on.
Import sugar and updated addEvents callbacks

Socket is now passed as the first parameter of each addEvents callback.