anchor.diff:          case Key of "" -> []; _ -> {keyfile, Key} end
       ]).
   
  -
  +%% @private
  +-spec handshake_req(inet:ip_address(), inet:port_number(), nksip_lib:proplist()) ->
  +    {binary(), #handshake{}}.
  +
  +handshake_req(Ip, Port, Opts) ->
  +    case nksip_lib:get_value(transport_uri, Opts) of
  +        #uri{domain=Domain, path=Path} ->
  +            Resource = binary_to_list(Path),
  +            Host = binary_to_list(Domain);
  +        undefined ->
  +            Host = binary_to_list(nksip_lib:to_host(Ip)),
  +            Resource = "/"
  +    end,
  +    {ok, #handshake{message=Msg1}=HS1} = wsock_handshake:open(Resource, Host, Port),
  +    #http_message{headers=Headers1} = Msg1,
  +    Headers2 = [{"Sec-Websocket-Protocol", "sip"}|Headers1],
  +    Msg2 = Msg1#http_message{headers=Headers2},
  +    HS2 = HS1#handshake{message=Msg2},
  +    {wsock_http:encode(Msg2), HS2}.
  +
  +
  +%% @private
  +-spec handshake_resp(binary(), #handshake{}) ->
  +    ok | {error, term()}.
  +
  +handshake_resp(Data, Req) ->
  +    case wsock_http:decode(Data, response) of
  +        {ok, Resp} ->
  +            case wsock_handshake:handle_response(Resp, Req) of
  +                {ok, #handshake{message=#http_message{headers=Headers}}} -> 
  +                    case nksip_lib:get_value("Sec-Websocket-Protocol", Headers) of
  +                        "sip" -> 
  +                            ok;
  +                        Other ->
  +                            lager:warning("Websocket server did not send protocol: ~p", 
  +                                         [Other]),
  +                            ok
  +                    end;
  +                {error, Error1} -> 
  +                    {error, Error1}
  +            end;
  +        {error, Error2} ->
  +            {error, Error2};
  +        Other3 ->
  +            {error, Other3}
  +    end.
  +
  
positive.code: 
  %% @private
  websocket_init(_TransportName, Req, [AppId, Transp, Opts]) ->
      Timeout = nksip_lib:get_value(timeout, Opts),
      {{RemoteIp, RemotePort}, _} = cowboy_req:peer(Req),
      Transp1 = Transp#transport{remote_ip=RemoteIp, remote_port=RemotePort},
      {ok, Pid} = nksip_connection:start_link(AppId, Transp1, self(), Timeout),
      {ok, Req, #ws_state{conn_pid=Pid}}.
  
  
  %% @private
  
negative.code:             {ok, Socket0} -> Socket0;
              {error, Error1} -> throw(Error1) 
          end,
          {Data1, HandshakeReq} = handshake_req(Ip, Port, Opts),
          case TranspMod:send(Socket, Data1) of
              ok -> ok;
              {error, Error2} -> throw(Error2)
          end,
          case TranspMod:recv(Socket, 0, 5000) of
              {ok, Data2} ->
                  case handshake_resp(Data2, HandshakeReq) of
                      ok -> ok;
                      {error, Error3} -> throw(Error3)
                  end;
              {error, Error4} ->
                  throw(Error4)
          end,
          {ok, {LocalIp, LocalPort}} = InetMod:sockname(Socket),
          Transp1 = Transp#transport{
  