Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use ChunkedStream properly
    primarykey
    data
    text
    <p>Here's my use case... I have an upstream service that sends my Netty app data over the network, and that data needs to be published to multiple clients connected to Netty. The data pushed to the clients must be HTTP "Transfer-Encoding: chunked."</p> <p>I found <code>ChunkedStream</code> and though that maybe I could create a <code>PipedInputStream</code> and a <code>PipedOutputStream</code> (connected to the <code>PipedInputStream</code>) and write the <code>ChunkedStream</code> to the channel. Then when data is received from my upstream service I could write the data into the <code>PipedOutputStream</code> of the channels and it'd be sent to the clients:</p> <p><strong>In channelConnected</strong></p> <pre><code>PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(in); ctx.getChannel().write( new PersistentChunkedStream(in) ); </code></pre> <p><strong>Separate thread publishes data to a connected channels</strong></p> <pre><code>ChannelBuffer buff = ChannelBuffers.copiedBuffer("FOO",CharsetUtil.UTF_8); out.write( buff.array() ); channel.get(ChunkedWriteHandler.class).resumeTransfer(); </code></pre> <p>I had to extend <code>ChunkedStream</code> to return <code>null</code> from <code>nextChunk</code> if there are 0 bytes available (to "suspend" the write without the thread hanging), so I call <code>resumeTransfer</code> after I write to the <code>PipedOutputStream</code> of the associated channel. When I debug and step through the code, I can see <code>flush</code> of <code>ChunkedWriteHandler</code> being called, which does call:</p> <pre><code>Channels.write(ctx, writeFuture, chunk, currentEvent.getRemoteAddress()); </code></pre> <p>with the bytes I wrote into the <code>PipedOutputStream,</code> but it's never received by the client.</p> <p><strong>HTTP curl</strong></p> <pre><code>~ $ curl -vN http://localhost:8080/stream * About to connect() to localhost port 8080 (#0) * Trying 127.0.0.1... connected * Connected to localhost (127.0.0.1) port 8080 (#0) &gt; GET /stream HTTP/1.1 &gt; User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3 &gt; Host: localhost:8080 &gt; Accept: */* &gt; &lt; HTTP/1.1 200 OK &lt; Transfer-Encoding: chunked &lt; ### NOTE: NO "FOO" TRANSMIT BACK ### </code></pre> <p>Any thoughts? Maybe there's a better way to accomplish this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload