anchor.diff:  handle_sock(ok, S = #state{socket=Sock, state=eof}) ->
       io:format("doing eof ~n"),
       case recv_repl(Sock) of
  -        {ok, Mode} ->
  -            Mode;
  +        {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}) -> % Remove 'mode=sync' ?
  +handle_sock(ok, S = #state{socket=Sock, state=load, mode=sync}) ->
       io:format("getting payload sync ~n"),
  -    case recv_payload(Sock) of
  -        {stream, Bulk} ->
  -            gen_server:cast(self(), {save_rdb, Bulk}),
  -            {noreply, S#state{state=lalala}}; % Next state will be 'lalala' % FIXME
  -        {error, Error} ->
  -            {stop, socket_err, {S, Error}}
  -    end;
  -
  -%% Receive the payload from de synchronization command 'psync'
  -handle_sock(ok, S = #state{socket=Sock, state=load, mode=psync}) -> % Remove 'mode=sync' ?
  -    io:format("getting payload psync ~n"),
  -    A = recv_payload(Sock),
  -    B = recv_payload(Sock),
  -    io:format("lookA -> ~p ~n", [A]),
  -    io:format("lookB -> ~p ~n", [B]),
  -    {noreply, S};
  +    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() ->
  
positive.code: connect(_, _) ->
      throw("invalid host or port to connect to").
  
  recv_payload(Sock) ->
      inet:setopts(Sock, [{active,once}]),
      receive
          {tcp, Sock, <<"+FULLRESYNC", _, RunId:40/binary, _, Offset/binary>>} ->
              {foo, b2l(RunId), int_offset(Offset)}; % Fix my name
          {tcp, _Sock, <<Bulk/binary>>} ->
              {stream, Bulk};
          {tcp, _Sock, Data} ->
              io:format("invalid data received '~p' ~n", [Data]),
              {error, "invalid data received"};
  
negative.code: %% API calls
  %%====================================================================
  start() ->
      gen_server:start_link({global, ?MODULE}, ?MODULE, [], []).
  
  stop() ->
      gen_server:call({global, ?MODULE}, shutdown).
  
  %%====================================================================
  %% gen_server callbacks
  