7

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?

Bill Brasky
  • 2,614
  • 2
  • 19
  • 20
  • If you're not tied to Netty, maybe you can try Jetty's SPDY, see http://webtide.intalio.com/2012/03/spdy-support-in-jetty/ and http://www.smartjava.org/content/how-use-spdy-jetty. – sbordet Apr 10 '12 at 07:53
  • 1
    @svordet Bill already has a server, he needs a client. – Slartibartfast Apr 10 '12 at 08:42
  • Actually, it looks like sbordet is correct; Jetty also has a SPDY client that might be easier to work with: http://wiki.eclipse.org/Jetty/Feature/SPDY#Using_SPDY_Client_Applications – Bill Brasky Apr 10 '12 at 17:10

2 Answers2

3

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.

Slartibartfast
  • 8,735
  • 6
  • 41
  • 45
  • Ah, so I just request multiple channels from the factory and under the hood the SPDY handlers will multiplex them? In what order should I add the handlers? – Bill Brasky Apr 10 '12 at 15:06
  • Unfortunately it's not that simple, but it is possible to make it using provided classes. I'm interested in making this work myself, so I'll try to build working code later. – Slartibartfast Apr 10 '12 at 15:37
2

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

Jos Dirksen
  • 1,863
  • 14
  • 13
  • Thanks for the answer, but I'm looking for the opposite. I want an HTTP *Client* that will use SPDY when available but fall back to regular HTTP. – Bill Brasky Apr 30 '12 at 15:45
  • Ah, like that. Then you can still use pretty much the same approach and set of handlers. But instead of using a ServerBootstrap, use a ClientBootstrap – Jos Dirksen Apr 30 '12 at 20:10