Added already implemented code

This is a large part of client.erl and the definition of the client
state in defs.hrl