Factor out the network related functions.
Adjust examples.