简体   繁体   English

播放框架Java分块响应

[英]play framework Java chunked response

I am trying for java chunked response part of play framework. 我正在尝试播放框架的Java块式响应部分。 But it is not working .It seems like client side will start getting the data until all data is provided in server side. 但是它不起作用。似乎客户端将开始获取数据,直到在服务器端提供所有数据为止。

Code is pretty much like this , passing an infinite string to chunks. 代码非常像这样,将无限字符串传递给块。

public static Result index() {
   // Prepare a chunked text stream
    Chunks<String> chunks = new StringChunks() {

        // Called when the stream is ready
        public void onReady(Chunks.Out<String> out) {
            while(true){
                 out.write("hello");
            }
        }
    };
   // Serves this stream with 200 OK
   return ok(chunks);
}

It just gets stuck forever, and I can receive nothing in browser or console. 它永远卡住了,我在浏览器或控制台中什么也收不到。

Is it the right way to pass an infinite string like this ? 这样传递无限字符串是正确的方法吗? If it is not , how can I pass infinite data or large file (chunked) to client side ? 如果不是,如何将无限数据或大文件(分块)传递给客户端?

My own stupid question. 我自己的愚蠢问题。 I blocked myself by making an infinite loop in its own thread. 我通过在自己的线程中进行无限循环来阻止自己。

Just create a new thread and everything will be fine 只需创建一个新线程,一切都会好起来的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM