Socket BUG on Windows 8 Consumer Preview + Visual Studio 11 Developer Preview

I am writing an application in Visual Studio 11 Developer Preview and I am getting this error after the application has been running with the reader for a while. InputStreamOptions = InputStreamOptions.Partial; set of options:

An unhandled exception of type 'System.Exception' occurred in mscorlib.dll

Additional information: The operation attempted to access data outside the valid range (Exception from HRESULT: 0x8000000B)

      

The socket can read the stream normally if this parameter is not set.

Here's the code for your reference:

   private StreamSocket tcpClient;
    public string Server = "10.1.10.64";
    public int Port = 6000;
    VideoController vCtrl = new VideoController();
    /// <summary>
    /// Initializes the singleton application object.  This is the first line of authored code
    /// executed, and as such is the logical equivalent of main() or WinMain().
    /// </summary>
   public App()
    {
        tcpClient = new StreamSocket();
        Connect();
        this.InitializeComponent();
        this.Suspending += OnSuspending;
    }

   public async void Connect()
   {
       await tcpClient.ConnectAsync(
                    new Windows.Networking.HostName(Server),
                    Port.ToString(),
                    SocketProtectionLevel.PlainSocket);

       DataReader reader = new DataReader(tcpClient.InputStream);
       Byte[] byteArray = new Byte[1000];
       //reader.InputStreamOptions = InputStreamOptions.Partial;
       while (true)
       {


           await reader.LoadAsync(1000);
           reader.ReadBytes(byteArray);

           // unsafe 
           //{
           //   fixed(Byte *fixedByteBuffer = &byteArray[0])
           //  {
           vCtrl.Consume(byteArray);
           vCtrl.Decode();
           // }
           //}
       }


   }

      

+3


source to share


1 answer


InputStreamOptions.Partial

means it LoadAsync

may terminate when less than the requested number of bytes are available. Therefore, you cannot read the full size of the required buffer.

Try the following:



public async void Connect()
{
  await tcpClient.ConnectAsync(
      new Windows.Networking.HostName(Server),
      Port.ToString(),
      SocketProtectionLevel.PlainSocket);

  DataReader reader = new DataReader(tcpClient.InputStream);
  reader.InputStreamOptions = InputStreamOptions.Partial;
  while (true)
  {
    var bytesAvailable = await reader.LoadAsync(1000);
    var byteArray = new byte[bytesAvailable];
    reader.ReadBytes(byteArray);

    // unsafe 
    //{
    //   fixed(Byte *fixedByteBuffer = &byteArray[0])
    //  {
    vCtrl.Consume(byteArray);
    vCtrl.Decode();
    // }
    //}
  }
}

      

By the way, the right place to report Microsoft bugs is Microsoft Connect .

+1


source







All Articles