Factor out client-server protocol into a separate module.