anchor.diff:      spawn(fun() -> loop(Socket, ?INIT, undefined) end),
       new_connection(Listen).
   
  -%% LS: Local socket which connect to the browser or client
  -%% ST: Session State
  -%% RS: Remote Socket which connect to the desired destination which browser or client want to connect.
  -
   loop(LS, ST, RS) ->
  -    %%io:format("start to receive data from socket ~p, state = ~p~n", [S, T]),
       {Result, Packet} = gen_tcp:recv(LS, 0, infinity),
       case Result of
           ok -> 
  -            %%io:format("received data  = ~p~n",[Data]),
               {State, RemoteSocket} = handle_connection_request(LS, RS, ST, Packet),
               loop(LS, State, RemoteSocket);
           error -> io:format("loop, Reason = ~p~n",[Packet]),gen_tcp:close(LS)
  
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: 
  handle_connection_request(LS, RS, ST, Packet) ->
      case ST of
          ?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_packet(LS, <<5, 0>>),
      {?HELLO, undefined}.
  
  handle_hello_request(LS, Packet) ->
      %%fetch the remote addr and remote port from the data.
      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}]),
  