long polling netty nio framework java

前端 未结 3 1315
野趣味
野趣味 2021-02-06 00:29

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

but waitforx is asynchronous because it has

3条回答
  •  粉色の甜心
    2021-02-06 00:59

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

提交回复
热议问题