Major refactoring of networking part.

Use objects instead of raw file descriptors.