长轮询网状NIO的java框架 [英] long polling netty nio framework java

查看:417
本文介绍了长轮询网状NIO的java框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用网状框架做长轮询?例如说我取的http://本地主机/ waitforx

How can I do long-polling using netty framework? Say for example I fetch http://localhost/waitforx

waitforx 是异步的,因为它必须等待一个事件?例如说这东西获取从阻塞队列(只能取时,在队列中的数据)。当从队列获取项目,我想发送的数据返回到客户端。希望有人可以给我一些提示,如何做到这一点。

but waitforx is asynchronous because it has to wait for an event? Say for example it fetches something from a blocking queue(can only fetch when data in queue). When getting item from queue I would like to sent data back to client. Hopefully somebody can give me some tips how to do this.

非常感谢

推荐答案

您可以先写一个响应头,再后来从其他线程发送体(内容)。

You could write a response header first, and then send the body (content) later from other thread.

void messageReceived(...) {
    HttpResponse res = new DefaultHttpResponse(...);
    res.setHeader(...);
    ...
    channel.write(res);
}

// In a different thread..
ChannelBuffer partialContent = ...;
channel.write(partialContent);

这篇关于长轮询网状NIO的java框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆