some useful code for network programming