manash
manash

Reputation: 7106

Protocol specific channel handlers

I'm writing an application server that will receive SIP and DNS messages from the network.

When I receive a message from the network, I understand from the documentation that at first, I get a ChannelBuffer. I would like to determine which kind of message has been received (SIP or DNS) and to decode it.

To determine the message type, I can dedicate port to each type of message, but I would be interested to know if there exist another solution for that. My question is more about how to decode the ChannelBuffer.

Is there a ChannelHandler provided by Netty to decode SIP or DNS messages? If not, what would be the right place in the type hierarchy to write my custom ChannelHandler?

To illustrate my question, let's take as example the HttpRequestDecoder, the hierarchy is:

java.lang.Object
    org.jboss.netty.channel.SimpleChannelUpstreamHandler
        org.jboss.netty.handler.codec.frame.FrameDecoder
            org.jboss.netty.handler.codec.replay.ReplayingDecoder<HttpMessageDecoder.State>
                org.jboss.netty.handler.codec.http.HttpMessageDecoder
                    org.jboss.netty.handler.codec.http.HttpRequestDecoder

Also, do I need to use two different ChannelHandler for decoding and encoding, or is there a possibility to use a single ChannelHandler for both?

Thanks

Upvotes: 0

Views: 568

Answers (1)

forty-two
forty-two

Reputation: 12817

If you really have a requirement for port unification (an example here), i.e. receiving different protocols on the same port, then you would have to detect the protocol in a handler and take appropriate actions. Could be as simple as inserting different handlers in the pipe line.

However, I find it very improbable that SIP and DNS would share the same port, hence no need to complicate matters.

I haven't seen a SIP decoder/encoder for Netty, but depending on what you want to do with the message, the HTTP decoder is a a very good starting point (and could be made simpler since chunking is not supported in SIP).

I would strongly recommend not to try to combine DNS and SIP decoding in one handler (or any other combination for that matter). Keep the handlers as simple and coherent as possible. Combine handlers instead, if needed.

Upvotes: 1

Related Questions