Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SPDY with Netty

Tags:

java

netty

spdy

I've set up MOD_SPDY on my Apache server and now want to retrofit my client code to use Netty's SPDY implementation to send my requests to the server over a SPDY channel.

This is my first experience using Netty, so I think I get that I need to somehow configure my Channel and then send requests through it. The problem is, that it doesn't seem very clear exactly how to configure the channels and even after that, how to track multiple HTTP requests inside the channel that might be executing concurrently.

I've googled around and found the SPDY package: http://netty.io/docs/stable/api/org/jboss/netty/handler/codec/spdy/package-summary.html

but the documentation is still quite thin there. I didn't seem to find any examples of using the code, only the announcement that it exists in the latest release.

Does someone have an example about how to construct a SPDY channel and then send/track multiple requests and responses through it? Also, how would this function when the server does not support SPDY and the channel falls back to a standard SSL connection?

like image 607
Bill Brasky Avatar asked Apr 09 '12 21:04

Bill Brasky


2 Answers

Only example I could find on Netty and SPDY is a test code for SessionHandler and socket echo test. I'm yet to make this thing running, but Your client should make pipeline consisting of SpdyFrameCodec, SpdySessionHandler and your handler.

Your handler should be modeled after EchoHandler in session test, because that way SpdySessionHandler does job of decoding raw frames into more meaningful ones and does some things as required by SPDY protocol.

As for fall-backing, there are SpdyHttpCodec in snapshot version of the Netty that translates from SPDY to HTTP. That way you can build your client handler in terms of HTTP and receive messages that came either through SPDY or HTTP transparently. To do this it is required to implement something similar to port unification example.

All that said. There is room for few utility classes/handlers to make all of this an "out of the box" experience. I wanted to make a working example, but am lacking time right now for it, and there would be too much code to simply paste it here as answer.

like image 58
Slartibartfast Avatar answered Nov 02 '22 07:11

Slartibartfast


There aren't much examples for using spdy with jetty. I'm usually not one for shameless promotion, but I just wrote down a complete example on how to do what you want. I've configured netty to serve spdy when the client supports it and fall back to http when spdy isn't available. You can find the code at: http://www.smartjava.org/content/using-spdy-and-http-transparently-using-netty

like image 2
Jos Dirksen Avatar answered Nov 02 '22 07:11

Jos Dirksen