anchor.diff:      ok = gen_tcp:send(S, mqtt_framing:serialise(Frame)),
       ok.
   
  +%% Send an RPC frame (one that expects a reply) and return a receipt
  +rpc(Conn, Frame, From) ->
  +    Ref = make_ref(),
  +    gen_fsm:send_event(Conn, {rpc, Frame, Ref, From}),
  +    {ok, Ref}.
  +
   %% Record the fact of an RPC and send the frame with the correct id.
  -rpc(S0, Req, From) ->
  +do_rpc(S0, Req, Ref, From) ->
       #state{ id_counter = Id,
               rpcs = RPC0 } = S0,
  -    RPC1 = gb_trees:insert(Id, From, RPC0),
  +    RPC1 = gb_trees:insert(Id, {Ref, From}, RPC0),
       write(S0, with_id(Id, Req)),
       S0#state{ id_counter = Id + 1, rpcs = RPC1 }.
   
  
positive.code:     write(S1, P1),
      {next_state, opened, S1};
  
  opened({rpc, Frame, From}, S0) ->
      S1 = rpc(S0, Frame, From),
      {next_state, opened, S1};
  
  opened({frame, Frame}, S0) ->
  
negative.code:           receiver_monitor = undefined
           }).
  
  -type(error() :: {'error', term()}).
  
  -type(connection() :: pid()).
  
  start_link() ->
      gen_fsm:start_link(?MODULE, [], []).
  
  -spec(connect(connection(), address(), client_id()) -> ok | error()).
  connect(Conn, Address, ClientId) ->
      connect(Conn, Address, ClientId, []).
  
  -spec(connect(connection(),
                address(),
                client_id(),
                [connect_option() | {'receiver', pid()}]) -> ok | error()).
  connect(Conn, Address, ClientId, ConnectOpts0) ->
      Connect = #connect{ client_id = iolist_to_binary([ClientId]) },
      Receiver = proplists:get_value(receiver, ConnectOpts0, self()),
  