Sunday, April 12, 2015

Java: Stream Control Transmission Protocol (SCTP)

If you have not heard about SCTP, don't fret! Me neither, until recently.

For a good explanation about SCTP, you can read this and this and this. In short, SCTP is basically TCP on steroids!

People who knows me well knew that I am always curious about new technology or technology new to me (sorry if I confuse you :).

How can I miss the chance to explore SCTP futher? Of course, the language of choice would be Java - still my favorite language after all these years.

First, I created the SctpServer class to serve as a SCTP server.
Next, I created the SctpClient class to serve as the SCTP client that will connect to multiple SCTP servers started on different ports (same host in this case) through a single socket (YES, you read it right, single socket!).

Two SctpServers listening on port 12000 and 12001. An SCTP client sends message to them on the same socket.
From the image above, you can see that there are 2 SctpServer listening on port 12000 and 12001 respectively.

Once the ScptClient connects to them and send them messages, you can see both servers reported that the connection came from port 43975 with stream number of 0 (SctpServer that listens on port 12000) and 1 (SctpServer that listens on port 12001) respectively.

SctpClient uses SctpMultiChannel for its communication.

Now, if you take a look at the codes for SctpClient, there is no "connect" statement at all. That is because a new association will automatically be created for every "send" command. [reference]

The destination of your message/data is now encapsulated in the MessageInfo object.

If you have the interest to explore SCTP further, you can download the sample codes here.

Enjoy hacking!

No comments:

Post a Comment