Deduplications of common parts.

Also, re-spliting base.py into base_service.py and base_client.py. They were getting huge and most of the protocol part happens in here now.