anchor.diff:  
   handle_connection_request(LS, RS, ST, Packet) ->
       case ST of
  -        ?INIT -> handle_init_request(LS, Packet);
  -        ?HELLO -> handle_hello_request(LS, Packet);
  +        ?INIT      -> handle_init_request(LS, Packet);
  +        ?HELLO     -> handle_hello_request(LS, Packet);
           ?CONNECTED -> handle_reply_request(RS, Packet);
           _Any -> io:format("Error for handle connection request"), error
       end.
   
   handle_init_request(LS, Packet) ->
  -    send_data(LS, <<5, 0>>),
  +    send_packet(LS, <<5, 0>>),
       {?HELLO, undefined}.
   
   handle_hello_request(LS, Packet) ->
       %%fetch the remote addr and remote port from the data.
  -    send_data(LS, <<5,0,0,1,0,0,0,0,16,16>>),
  +    send_packet(LS, <<5,0,0,1,0,0,0,0,16,16>>),
       {Addr, Port} = parse_destination_addr(Packet),
       %%todo connection may be failed here, do we need to reconnect?
       {Result, RS} = gen_tcp:connect(Addr, trs_port(Port),[binary, {active,false}, {packet,0}]),
  
positive.code: async_send_to_local() ->
      receive
          {ok, LS, Packet} -> 
              send_data(LS, Packet),
              async_send_to_local()
      end.
  
  
  send_data(Socket,Data) ->
      gen_tcp:send(Socket,Data).
  
  
  parse_destination_addr(Data) ->
      <<_:3/binary,T,_/binary>> = Data,
      %%io:format("The type of request destination is ~B~n",[T]),
      case T of
         16#01 -> 
              <<_:3/binary,T,Addr:4/binary,Port:2/binary>> = Data, 
              {list_to_tuple(Addr), Port};
         16#03 ->
              <<_:3/binary,T,N,URL:N/binary,Port:2/binary>> = Data,
              {url_to_ip(binary_to_list(URL)), Port};
         16#04 ->
              <<_:3/binary,T,Addr:16/binary,Port:2/binary>> = Data,
              {list_to_tuple(Addr), Port}
      end.
  
  
negative.code: -define(INIT, init).
  -define(HELLO, hello).
  -define(CONNECTED, connected).
  -define(SOCKS_PORT,douban).
  
  -type state() :: init|hello|connected.
  
  -spec loop(LocalSocket, State, RemoteSocket) -> any() when
      LocalSocket :: gen_tcp:socket(),
      State :: state(),
      RemoteSocket :: gen_tcp:socket().
  
  -spec handle_connection_request(LocalSocket, RemoteSocket, State, Packet) -> {state(),gen_tcp:socket()} when
      LocalSocket :: gen_tcp:socket(),
      RemoteSocket :: gen_tcp:socket(),
      State :: state(),
      Packet :: binary().
  
  start_socks() ->
      start_socks(?SOCKS_PORT).
  
  start_socks([Port|_]) ->
      try
          start_socks(list_to_integer(Port))
      catch
          error:Reason -> error_msg("start socks proxy failed, reason = ~p~n",[Reason])
      end;
      
  start_socks(Port) ->
      init(),
      {Result, Listen} = gen_tcp:listen(Port,[binary,{active,false},{packet,0}]),
      case Result of
  