updated with modern socket programming style