Moved most of code into network library
Merge branch 'tcptest2'