简体   繁体   English

long polling netty nio framework java

[英]long polling netty nio framework java

How can I do long-polling using netty framework? 如何使用netty框架进行长轮询? Say for example I fetch http://localhost/waitforx 比方说,我获取http://localhost/waitforx

but waitforx is asynchronous because it has to wait for an event? waitforx是异步的,因为它必须等待事件? 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. 希望有人可以给我一些如何做到这一点的提示。

Many thanks 非常感谢

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);

You can use netty-socketio project. 您可以使用netty-socketio项目。 It's implementation of Socket.IO server with long polling support. 它是Socket.IO服务器的实现,具有长轮询支持。 On web side you can use Socket.IO client javascript lib. 在Web端,您可以使用Socket.IO客户端 javascript lib。

You could also do the following in [sfnrpc]: http://code.google.com/p/sfnrpc 您还可以在[sfnrpc]中执行以下操作: http//code.google.com/p/sfnrpc

Object object = RPCClient.getInstance().invoke("#URN1","127.0.0.1:6878","echo",true,60,"", objArr,classArr, sl);

The true causes communication to be synchronous. 真正的原因是沟通是同步的。

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

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