anchor.diff:              throw(OtherSendError)
       end.
   
  -connect(Addr, Port) when is_tuple(Addr), is_integer(Port) ->
  -    case tcp_connect(Addr, Port) of
  -        {ok, Sock} ->
  -            Sock;
  -        {error, Error} ->
  -            throw(Error)
  -    end;
  -connect(_, _) ->
  -    throw("invalid host or port to connect to").
  -
  -recv_once(Sock) ->
  +recv_sock(Sock) ->
       inet:setopts(Sock, [{active,once}]),
       receive
  +        % "-LOADING"
  +        {tcp, Sock, <<"+OK", _/binary>>} ->
  +            {ok, psync};
  +        {tcp, Sock, <<"+PONG", _/binary>>} ->
  +            {ok, pong, Sock};
           {tcp, Sock, <<"+FULLRESYNC", _, RunId:40/binary, _, Offset/binary>>} ->
               {ok, fullresync, b2l(RunId), int_offset(Offset)};
  +        {tcp, _Sock, <<"-ERR Unrecognized REPLCONF", _/binary>>} ->
  +            {ok, sync};
           {tcp, _Sock, <<Bulk/binary>>} ->
               {ok, load_stream, Bulk};
           {tcp, _Sock, Data} ->
  
positive.code:     {ok, State}.
  
  %% Server termination
  terminate(socket_err, {S, Error}) ->
      gen_tcp:close(S#state.socket),
      io:format("Error over socket ~p ~n", [Error]);
  terminate(Reason, State) ->
      gen_tcp:close(State#state.socket),
      io:format("Generic termination: '~p' '~p'~n",[Reason, State]).
  
negative.code:     Sock = connect(Addr, Port),
      case ping(Sock) of
          ok ->
              recv_sock(Sock);
          {error, timeout} ->
              io:format("Send timeout, closing! ~n"),
              gen_tcp:close(Sock),
  