using thread and pipes to replace sockets