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

This is a work in progress, so there could be improvement later on.