Search code examples
c#socketswindows-phone-8windows-runtimedatareader

LoadAsync WP8.1 : Partial result


I'm currently on a project to port the Android version of a live streaming SDK to its WP 8.1 version. I'm trying to request for a path list to the server (SERVER B) through socket streams. Here is how I do it:

DataReader reader = new DataReader(socket.InputStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
List<byte> byteList = new List<byte>();
while (true)
{
    uint bytesAvailable = await reader.LoadAsync(1);
    if (bytesAvailable == 0) break;
    byte[] arrayByte = new byte[bytesAvailable];
    reader.ReadBytes(arrayByte);
    for (int j = 0; j < arrayByte.Length; j++)
    {
        byteList.Add(arrayByte[j]);
    }
}

Since I do not know the initial length, I'm loading it per byte. When I call

byteList.Count();

It always returns 16 which is only a partial result.

Weirdly enough, I had tried receiving bytes from another server (SERVER A) to get a channel list,

// Read from the stream socket
DataReader msgToRead = new DataReader(socket.InputStream);
msgToRead.InputStreamOptions = InputStreamOptions.Partial;
uint bytesAvailable = await msgToRead.LoadAsync(224);
byte[] byteArray = new byte[bytesAvailable];
msgToRead.ReadBytes(byteArray);
byteList = byteArray.ToList();

It loads the whole byte in one-go.

I tried to apply this piece of code to interact with SERVER B, but the byteList still returns a length of 16.

What should I do?


Solution

  • My bad. This is my mistake. So the way the server works is it deploys responses based on the request message (channel ID query) from the SDK/client app. I found out that I requested for the wrong channel ID and that's why the server was not responding the way it's supposed to be.

    Thank you very much for trying to help me though.