Sockets secure implementations

Rebased on `master`.
nit: This block of code is repeated a bunch - make a helper? `addSelectorMessage(socket, TYPE, null);`