WP8.1 HttpClient Stream only received 65536 bytes of data

I am trying to record a realtime flv stream demplex in windows-runtime, for win8.1 and wp8.1 MediaElement.

I have finished the demux code already, flv files can be demuxed properly in h264 and aac tags.

When I tried to play network files and streams I got a very strange network problem:

The same code,

  • runs under win8.1, all good, any files or network streams (proves the demux code is fine);
  • runs under wp8.1 (real phone or emulator), files are good, network streams are bad - no matter how I read bytes from the HttpClient stream, the target server only gives me 65536 bytes of data and then the connection chokes, no response and no error, and even without a timeout, it just suffocates the flow.

Code for opening a stream:

var uri = new Uri("http://hdl.xxx.com/live/yyyy")
//uri is dymatic
var client = new HttpClient();
var stream = await client.GetStreamAsync(uri);
openStream(stream)

      

Code for reading data:

public static byte[] ReadBlocks(this Stream stream, int count)
{
    byte[] buffer = new byte[count];
    int offset = 0;
    int length;

    while (offset < count)
    {
        //a loop statement to guarantee I can get *count* bytes
        Debug.WriteLine("read " + (count - offset));
        //a debug message show how many bytes do I need
        length = stream.Read(buffer, offset, count - offset);
        if (length == 0)
        {
            throw new EndOfStreamException();
        }
        Debug.WriteLine("got " + length);
        //a debug message show how many bytes I got
        offset += length;
    }
    return buffer;
}

      

For example, when I need a rea ​​of ​​1024 bytes from a flv stream, I run stream.ReadBlocks (1024) under wp8.1, debug tells me how:

read 1024
got 768
read 256

      

and then nothing happened. I wrote an extra counter, the counter shows, once the server has sent a total of 65536 bytes, the next Read Read method will always be suppressed.

I'm pretty sure the uri is available. I can download some stream data as FLV file using pc web browser and this downloaded FLV file can be played in wp8.1 too.

Seems like this problem only occurs with wp8.1, android and ios are not affected.

So is this my code problem, or is the server actually configured incorrectly?

For the past three weeks, I've tried every http method that could open a stream, but still drowned out at 65536 bytes.

Can someone help me please?

+3


source to share


1 answer


I just solved the same problem - DO NOT use System.Net.HttpClient but Windows.Web.Http.HttpClient



System.Net uses the default Connection: Close header, which causes the stream to close, read only 65 kB. It also contains a bug that prevents you from overriding the Keep-Alive header (it throws some kind of nonesense exception)

+2


source







All Articles