Search |
||
Writing a TCP/UDP stack supporting the SIP protocol using the Grizzly Framework, part IIPosted by jfarcand on June 25, 2008 at 2:28 PM PDT
Back to technical blog after "buzzwording" for too long :-). Time to resume the tutorial about Grizzly and SIP. The first part was explaining Grizzly's server side components, this time I will concentrate on the client components. Like for the first part, I will not yet jump into the details of the SIP protocol. As for the server side, you first need to create the entry point in Grizzly, which is the Controller. Next, we need to configure which transport we want to support. For this blog purpose, I will only explain how to support UDP and TCP, and talk about TLS later. In Grizzly, a transport is represented using the ConnectorHandler interface, and the framework support by default three implementation: TCPConnectorHandler, TLSConnectorHandler and UDPConnectorHandler. By default, the Controller support TCP, but to help understanding how it works, the code below will explicitly configure the Controller to support TCP and UDP: Next we need to decide if we want to use a ProtocolChain for handling our request/response, or use a CallbackHandler to experiment with the bytes and the state of the connection. Since SIP is a two way protocol (the client can become the server and vice versa), let's first demonstrate how to use a ConnectorHandler with a ProtocolChain. For the purpose of this blog, let's add a (LogFilter) that output the bytes sent by the server: That means that once we are connected to a remote server, all the bytes we are getting back will be processed by the ReadFilter and LogFilter. So let's connect: What is interesting here is the ProtocolChain used for reading the bytes can also be used on the server side. So let's say we wrote a SipParserProtocolFilter, we can use that ProtocolFilter for parsing the bytes send by a remote client and also we can use it to parse the response we are getting when connecting to a remote server: Graphically, it looks like the following: ![]() Now let's assume we want to use the ConnectorHandler for read and write operations, but this time without using a ProtocolChain. The component we can use in that case is called a CallbackHandler. In the example above, we haven't created any CallbackHandler, but under the hood, Grizzly created one (the DefaultCallbackHandler), which dispatch all connect, read and write operations to the ProtocolChain. By default, the CallbackHandler interface, which is invoked by the Controller every time there is an asynchonous operations ready to be processed, looks like: As an example, here is a simple implementation of a CallbackHandler connect, read and write operations: With the example above, you can always decide to delegate the processing of the bytes to your ProtocolChain, which wasn't the case with my first example. Graphically, it looks like: ![]() To configure your CallbackHandler, you just need to pass an instance when executing the asynchronous connect operation: The only difference here is instead of passing a null, we are passing an instance of CallbackHandler. What I like with CallbackHandler is that I can decide when I want to delegate the processing to a ProtocolChain, and completely ignore that component if I don't want to write ProtocolFilter. And when I write a non blocking client, I can always decide to either write a CallbackHandler, or a simple ProtocolFilter. OK, hopefully the next blog for that serie will happens sooner. Next time I will start digging about SIP and how we have implemented it in Sailfin. »
Related Topics >>
Glassfish Comments
Comments are listed in date ascending order (oldest first)
Submitted by survivant on Fri, 2008-07-04 17:30.
ok.. c'est plus fort que moi..
Pipeline mySharedPipeline = new DefaultPipeline();
28 pipeline.setMaxThreads(5);
29
should be :
28 mySharedPipeline .setMaxThreads(5);
One question... why you don't include a zip file of your samples in your blog ?
Submitted by survivant on Thu, 2008-07-03 11:27.
I think your sample doesn't compile
look at the lines
19 TCPSelectorHandler tcpSelector = new TCPSelectorHandler();
20 tcpSelectorHandler.setPort(8080);
21 controller.addSelectorHandler(tcpSelector);
the variable is tcpSelector and the line later it's called : tcpSelectorHandler
unless the variable tcpSelectorHandler is declare somewhere else.
same thing for the UDP
Submitted by survivant on Thu, 2008-07-03 11:30.
line 27 there is a ")" trailing at the end..
you should test your code before posting :)
Submitted by kram on Mon, 2008-07-14 04:14.
One more thing :)
Line 53,
ch.connect(new InetSocketAddress("localhost",8080),null);
Gives an error:
"The method connect(SocketAddress, CallbackHandler) is ambiguous for the type ConnectorHandler"
so just need to cast the null to a CallbackHandler:
connectorHandler.connect(new InetSocketAddress("localhost",8080), (CallbackHandler)null);
Cheers,
Mark
Submitted by r1_rajeswari on Sun, 2008-10-05 23:31.
Hi Jean,
I need to built a gateway/proxy for communication between a TCP stack and a sip server. The flow would be:
SIP server<-> Proxy(using Grizzly framework)<-> TCP stack.
The functionalities of the proxy would be:
1. Understand TCP messages and convert them to SIP messages.
2. Send the SIP messages to a sip server.
3. Understand SIP messages and convert them to TCP messages and send them to the TCP stack.
In between the TCP stack and the sip server I need some kind of gateway to translate TCP messages to SIP and vice versa.
I need to built that gateway/proxy kind.
Please can anyone suggest whether this can be done using Grizzly framework.
Submitted by nikhil_garg on Tue, 2009-05-05 04:32.
Hi,
I am new to Grizzly framework. I tried to run the SipServerDemo code in eclipse.I have included the grizzly-nio-framework 1.9.15.jar in the eclipse.But i saw the Pipeline and DefaultPipeline classes are missing in the jar.Can somebody assist me on this.
Submitted by nikhil_garg on Wed, 2009-05-06 06:23.
thanks for your suggestion.I used sailfin to register the sip clients.As the post written by one of the users i wanted grzzley framework to be an interface between a client and server which can take TCP messages from client convert it to SIP messages and then send these messages to the sip server.This server should then decode the messages and send back to the client interface.
In short client and server communication through grizzly framework. Any assistance with this.
Submitted by nikhil_garg on Wed, 2009-05-06 11:16.
Hi,
I am using one of the gaming server from sun which is Project Darkstar.I have a gaming client and a server. I need to communicate between them using SIP messages so I need to use grizzly framework.
I wanted to use this because even in Project Darkstar the communication between client and server is through NIO.
This is what i want to achieve.
Submitted by nikhil_garg on Thu, 2009-05-07 23:31.
Hi,
Can you plz tell me as to how should i approach in setting up this framework.I am not able to get as how to start (I have to make some *.sar file and deploy in sailfin?? or what)
I need some assistance.
Thanx in advance.
Submitted by jfarcand on Fri, 2009-05-08 06:28.
@nikhil_garg Please follow the discussion via the users@grizzly.dev.java.net. You can use Nabble -> http://www.nabble.com/(Getting-started-with-Grizzly)-Re%3A--Jean-Francois-Arcand%27s-Blog--New-Comment-Posted-to-%27Writing-a-TCP-UDP-stack-supporting-the-SIP-protocol-using-the-Grizzly-Framework%2C-part-II%27-td23445990.html
|
||
|
|