anchor.diff:  %% ===================================================================
   
   
  -%% @private
  -start_tcp(AppId, Ip, Port, Socket, Pid) ->
  -    gen_tcp:close(Socket),
  +% %% @private
  +start_tcp(AppId, Ip, Port, Pid) ->
       case nksip_transport:start_transport(AppId, tcp, Ip, Port, []) of
  -        {ok, _} -> ok;
  -        {error, _} -> gen_server:cast(Pid, no_matching_tcp)
  +        {ok, TcpPid} -> gen_server:cast(Pid, {matching_tcp, {ok, TcpPid}});
  +        {error, Error} -> gen_server:cast(Pid, {matching_tcp, {error, Error}})
  +    end.
  +
  +%% @private Checks if a port is available for UDP and TCP
  +-spec open_port(nksip:app_id(), inet:ip_address(), inet:port_number(), integer()) ->
  +    {ok, port()} | {error, term()}.
  +
  +open_port(AppId, Ip, Port, Iter) ->
  +    Opts = [binary, {reuseaddr, true}, {ip, Ip}, {active, once}],
  +    case gen_udp:open(Port, Opts) of
  +        {ok, Socket} ->
  +            {ok, Socket};
  +        {error, eaddrinuse} when Iter > 0 ->
  +            lager:warning("UDP port ~p is in use, waiting (~p)", [Port, Iter]),
  +            timer:sleep(1000),
  +            open_port(AppId, Ip, Port, Iter-1);
  +        {error, Error} ->
  +            {error, Error}
       end.
   
   
  
positive.code:             end;
          {rnrn, More} ->
              parse(More, Ip, Port, State);
          {error, Error} ->
              ?notice(AppId, "error ~p processing UDP msg", [Error])
      end.
  
negative.code:     gen_server_init(#state{}).
  
  init([AppId, #transport{listen_ip=Ip, listen_port=Port}=Transp]) ->
      case open_port(AppId, Ip, Port, 5) of
          {ok, Socket}  ->
              process_flag(priority, high),
              {ok, Port1} = inet:port(Socket),
              Self = self(),
              spawn(fun() -> start_tcp(AppId, Ip, Port1, Self) end),
              Transp1 = Transp#transport{local_port=Port1, listen_port=Port1},
              nksip_proc:put(nksip_transports, {AppId, Transp1}),
              nksip_proc:put({nksip_listen, AppId}, Transp1),
              State = #state{
                  app_id = AppId, 
                  transport = Transp1, 
                  socket = Socket,
                  tcp_pid = undefined,
                  stuns = []
              },
              {ok, State};
          {error, Error} ->
              ?error(AppId, "B could not start UDP transport on ~p:~p (~p)", 
                     [Ip, Port, Error]),
              {stop, Error}
      end.
  