locked
WinRT - StreamSocket - Connection closing while reading data via LoadAsync

    Question

  • I'm trying to send HTTP requests via StreamSocket, but response is truncated with

    "failedWinRTError: The object has been closed."


    Here is my code:

    var count, hostName, raw_request, raw_response, reader, socketProtection, startReader, streamSocket, writer;
      streamSocket = new Windows.Networking.Sockets.StreamSocket();
    
      hostName = new Windows.Networking.HostName("http://www.reddit.com", "80");
    
      raw_response = "";
    
      count = 0;
    
      startReader = function() {
        return reader.loadAsync(8 * 1000).done(function(bytesRead) {
    
          raw_response += reader.readString(reader.unconsumedBufferLength);
          if (raw_response.indexOf("</html>") > 0) {
            return;
          } else {
            startReader();
          }
        }, function(error) {
    
          raw_response += reader.readString(reader.unconsumedBufferLength);
          window.raw_response = raw_response;
          return;
        });
      };
    
      streamSocket.connectAsync("http://www.reddit.com", "80", 0).done(function(response) {
        var string;
    
        reader = new Windows.Storage.Streams.DataReader(streamSocket.inputStream);
        reader.inputStreamOptions = 1;
    
        writer = new Windows.Storage.Streams.DataWriter(streamSocket.outputStream);
        string = "Hello world";
        writer.writeString(raw_request);
        return writer.storeAsync().done(function() {
          writer.flushAsync();
          writer.detachStream();
          return startReader();
        });
      });

    I noticed that the beginning of the response is truncated as well.

    This is what I get at the beginning of HTTP responses.

    /1.1 200 OK

    Also strangely... HTTPS requests work perfectly.


    Any idea what I'm doing wrong? Thanks :)

    Sunday, January 20, 2013 4:09 PM

Answers

  • Hi,

    Fiddler capture http traffic. Wireshark capture http and tcp traffic. Just have a try, any more question, please feel free to reply.


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Friday, January 25, 2013 9:58 AM
    Wednesday, January 23, 2013 1:58 AM

All replies

  • Hi,

    Do you debug with wireshark? Please post here if you find anything.


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 22, 2013 8:39 AM
  • Hi thanks for the reply!

    I've been trying to use Fiddler, but it doesn't seem to capture socket connections.

    I'll try with Wireshark. Thanks.

    Tuesday, January 22, 2013 11:50 AM
  • Hi,

    Fiddler capture http traffic. Wireshark capture http and tcp traffic. Just have a try, any more question, please feel free to reply.


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Friday, January 25, 2013 9:58 AM
    Wednesday, January 23, 2013 1:58 AM