locked
MessageWebSocket: connectAsync returns parameter is incorrect RRS feed

  • Question

  • Hello guys.

    I've built a small demo site which is is hosted in IIS 8 and which exposes a web socket through a ashx file. I've already tested it with a client JS page and I've confirmed that it's working. Now, I'm trying to connect to it from a Metro app with the following code:

    var baseUrl = "http://localhost/sockets/socket.ashx";

    var username = document.getElementById("username").value;
    var url = baseUrl + "?username=" + username;
    socket = new Windows.Networking.Sockets.MessageWebSocket();
    socket.addEventListener("messagereceived", mensagemRecebida);
    socket.addEventListener("closed", socketEncerrado);
    var uri = new Windows.Foundation.Uri(url);
    return socket.connectAsync(uri)
                .then(function () {
                    divLogin.style.display = "none";
                    divDados.style.display = "";
                    imprimeMsg("Ligado ao servidor");
                });

    At runtime, the program ends during the connectAsync method call with the following error:

    Unhandled exception at line 29, column 9 in ms-appx://568d5f91-be07-48bc-aa7d-173987f279c4-t2ggmrgk4m9fg/js/default.js
    0x80070057 - JavaScript runtime error: The parameter is incorrect.
    WinRT information: uri
    File: default.js, line: 29 column: 9

    I've already checked all the network related capabilities, so I'm guessing that the problem is related with the URI I'm passing in. The docs say that is should receive an Uri, so I'm not sure on what's going on here...Any clues?

    Thanks.


    Luis Abreu

    Wednesday, April 18, 2012 9:27 AM

Answers

  • Hello Jeff.

    Nop, that was not it (btw, I'm almost positive that vs 11 beta already does all the work necessary to allow the communication with my machine). It's event worse than that: I was using the wrong scheme (should be ws and not http). really stupid, stupid mistake...


    Luis Abreu

    Wednesday, April 18, 2012 1:46 PM

All replies

  • Hi Luis,

    Metro apps are sandboxed and you cannot communicate with other applications on the same box.

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh780593.aspx

    You can temporarily disable this (see above for localhost) but you cannot ship an app that comminicates with localhost.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, April 18, 2012 12:05 PM
    Moderator
  • Hello Jeff.

    Nop, that was not it (btw, I'm almost positive that vs 11 beta already does all the work necessary to allow the communication with my machine). It's event worse than that: I was using the wrong scheme (should be ws and not http). really stupid, stupid mistake...


    Luis Abreu

    Wednesday, April 18, 2012 1:46 PM
  • Glad you found the problem my friend!

    Jeff Sanders (MSFT)

    Wednesday, April 18, 2012 1:49 PM
    Moderator
  • Spoke too soon...

    now, I've got another one...can only receive one message from the server. the second will always throw an exception (0x80072efe - JavaScript runtime error: Unknown runtime error) when I try to get the reader from the parameter that is sent to the function that handles the messagereceived event:

    function mensagemRecebida(e) {
            var reader = e.getDataReader(); //works for the first received message
            var totalChars = reader.unconsumedBufferLength;
            if (totalChars <= 0) return;
            var aux = JSON.parse(reader.readString(totalChars));
            imprimeMsg(aux.utilizador + "[" + aux.data + "]: " + aux.texto);
    }

    I've tried detaching the buffer before the end of the function, but it won't still solve the problem. I've already opened the web sockets project (from the samples) and I really don't see anything different from my code...

    ideas?


    Luis Abreu

    Wednesday, April 18, 2012 2:17 PM
  • anyone has make it work? 

    thanks.


    Luis Abreu

    Thursday, April 19, 2012 2:19 PM