anchor.diff:  connect(_, _) ->
       throw("invalid host or port to connect to").
   
  -recv_payload(Sock) ->
  +recv_once(Sock) ->
       inet:setopts(Sock, [{active,once}]),
       receive
           {tcp, Sock, <<"+FULLRESYNC", _, RunId:40/binary, _, Offset/binary>>} ->
  -            {foo, b2l(RunId), int_offset(Offset)}; % Fix my name
  +            {fullresync, b2l(RunId), int_offset(Offset)}; % Fix my name
           {tcp, _Sock, <<Bulk/binary>>} ->
  -            {stream, Bulk};
  +            {load_stream, Bulk};
           {tcp, _Sock, Data} ->
               io:format("invalid data received '~p' ~n", [Data]),
               {error, "invalid data received"};
  
positive.code: 
  %% Server termination
  terminate(socket_err, {S, Error}) ->
      io:format("Error over socket ~p ~n", [Error]),
      gen_tcp:close(S#state.socket);
  terminate(Reason, State) ->
      io:format("Generic termination: '~p' '~p'~n",[Reason, State]).
  
  %
  
negative.code: handle_sock(ok, S = #state{socket=Sock, state=eof}) ->
      io:format("doing eof ~n"),
      case recv_repl(Sock) of
          {ok, Type} ->
              gen_server:cast(self(), Type),
              {noreply, S#state{state=load, mode=Type}};
          {error, Error} -> % BUG in here!!
              {stop, socket_err, {S, Error}}
      end;
  %% Receive the payload from de synchronization command 'sync'
  handle_sock(ok, S = #state{socket=Sock, state=load, mode=sync}) ->
      io:format("getting payload sync ~n"),
      handle_recv(recv_once(Sock), S);
  
  handle_sock(ok, S = #state{socket=Sock, state=load, mode=psync}) ->
      io:format("getting payload psync 1st ~n"),
      handle_recv(recv_once(Sock), S);
  
  handle_sock(get_payload, S = #state{socket=Sock, state=payload, mode=psync}) ->
      io:format("getting payload psync 2nd ~n"),
      handle_recv(recv_once(Sock), S);
  
  handle_sock({error, Error}, S) ->
      {stop, socket_err, {S, Error}};
  handle_sock(_,_) ->
      {stop, general, "general socket error"}.
  
  
  handle_recv({fullresync, RunId, Offset}, S) ->
      gen_server:cast(self(), psync),
      {noreply, S#state{state=payload, runid=RunId, offset=Offset}}; % Next state will be 'payload'
  handle_recv({load_stream, Bulk}, S) ->
      gen_server:cast(self(), {save_rdb, Bulk}),
      {noreply, S#state{state=payload}}; % Next state will be 'payload'
  handle_recv({error, Error}, S) ->
      {stop, socket_err, {S, Error}}.
  
  
  initial() ->
  