WP8.1 HttpClient Stream got only 65536 bytes data

十年热恋 提交于 2019-12-23 16:32:35

问题


I am trying write a real-time flv stream demuxer on windows-runtime, for win8.1 and wp8.1's MediaElement.

I've already finish the demux code, flv files can be correctly demuxed into h264 and aac tag-datas.

When I was trying to play network files and streams, I got a very strange network problem:

The same code,

  1. run under win8.1, all good, whatever files or network streams (proves demux code is ok);
  2. run under wp8.1 (real phone or emulator), files are good, network streams are bad - no matter how I read bytes from HttpClient Stream, the target server only gives me 65536 bytes data, and then the connection is choked, no any response and error, and even no timeout, it's just choking the thread.

Code for opening the 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 the 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 to rea 1024 bytes from the flv stream, I run stream.ReadBlocks(1024) under wp8.1, the debug tells me like:

read 1024
got 768
read 256

and then nothing happend any more. I wrote an extra counter, the counter shows once server send a total of 65536 bytes, next Read method of stream will always be choked.

I'm sure the uri is available. I can download some stream data as a flv file by using pc web browser, and this downloaded flv file can be played under wp8.1 as well.

It looks like this problem only happens under wp8.1, android and ios are not affected.

So is it my code's problem or actually the server is not set up properly?

From last three weeks, I've tried every http method that can open a stream, but still got choked at 65536 bytes.

Could someone help me, please?


回答1:


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

The one in System.Net uses header Connection: Close by default, which causes the stream to close, reading only 65 kB. It also contains a bug which prevents you to override the header to Keep-Alive (it throws some nonesense exception)



来源:https://stackoverflow.com/questions/25800284/wp8-1-httpclient-stream-got-only-65536-bytes-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!