anchor.diff:  flip_send(Client, Data) ->
       gen_tcp:send(Client, flip(Data)).
   
  -forward(flip_recv, Client, Remote, From) ->
  -    try
  -        {ok, Packet} = flip_recv(Client, 0),
  -        ok = gen_tcp:send(Remote, Packet)
  -    catch
  -        Error:Reason ->
  -            io:format("Client: ~p ~p ~p.~n", [Client, Error, Reason]),
  -            From ! {close},
  -            exit({Error, Reason})
  -    end,
  -    forward(flip_recv, Client, Remote, From);
  -
  -forward(flip_send, Client, Remote, From) ->
  +forward(Client, Remote, From) ->
       try
           {ok, Packet} = gen_tcp:recv(Client, 0),
           ok = flip_send(Remote, Packet)
       catch
           Error:Reason ->
  -            io:format("Client: ~p ~p ~p.~n", [Client, Error, Reason]),
               From ! {close},
               exit({Error, Reason})
       end,
  -    forward(flip_send, Client, Remote, From).
  -
  -%% back，接受front的连接与认证，并接收加密的包解密后当作普通包处理。
  -%% back -- remote，Raw
  -%% remote -- back，Raw
  -%% back -- front，Flip
  +    forward(Client, Remote, From).
  +
  +heart() ->
  +    timer:sleep(10000),
  +    io:format(".~n"),
  +    heart().
  +
   back_start() ->
  -    {ok, Socket} = gen_tcp:listen(?BACK_PORT, [{reuseaddr, true},
  -                                               {active, false},
  -                                               binary]),
  +    back_start(['0.0.0.0', ?BACK_PORT]).
  +
  +back_start([Port]) ->
  +    back_start(['0.0.0.0', Port]);
  +back_start(Args) ->
  +    % prevent disconnect when run in ssh
  +    spawn(?MODULE, heart, []),
  +    [BackAddressStr, BackPortStr] = atoms_to_lists(Args, []),
  +    BackPort = list_to_integer(BackPortStr),
  +    {ok, BackAddress} = inet:getaddr(BackAddressStr, inet),
  +    io:format("back listen at ~s:~p.~n", [BackAddressStr, BackPort]),
  +    {ok, Socket} = gen_tcp:listen(BackPort, [{reuseaddr, true},
  +                                             {active, false},
  +                                             {ifaddr, BackAddress},
  +                                             binary]),
       back_accept(Socket).
  +
   
   back_accept(Socket) ->
       {ok, Client} = gen_tcp:accept(Socket),
  
positive.code:                 gen_tcp:close(Back)
          end
      catch
          _:_ ->
              gen_tcp:close(Client)
      end.
  
  
  start() ->
      spawn(?MODULE, back_start, []),
      spawn(?MODULE, front_start, []),
      receive
          {close} ->
              exit({done})
      end.
  
  socks5_handshake(Client) ->
  
negative.code: %%% 支持Socks5协议的高速加密通信的代理服务器脚本
  -module(proxy).
  -export([
      start/0
  ]).
  
  -export([
      back_start/0, back_start/1,
      back_accept/1,
      back_process/1,
  
      front_start/1,
      front_accept/3,
      front_process/3,
      forward/3,
  
      flip/1,
      flip_recv/2, flip_recv/3,
      flip_send/2,
  
      heart/0
  ]).
  
  -define(FRONT_PORT, '8780').
  -define(BACK_PORT, '8781').
  -define(CONNECT_TIMEOUT, 5000).
  
  -define(PASSWORD, "abcd1234").
  -define(PASSWORD_LENGTH, length(?PASSWORD)).
  
  %% socks constants
  -define(IPV4, 1).
  