Thursday, July 2, 2009

Java SCTP kick off

Overview

The SCTP API is defined in the com.sun.nio.sctp package and is built into rt.jar, therefore it is available on all OpenJDK supported platforms. Code completion, API documentation, etc, should work in your favorite editor. However, the implementation only provides support on Solaris and Linux. So you can use platforms like Windows to develop your SCTP applications, but you must deploy on Solaris or Linux.
Getting Setup

First you must have a JDK with the SCTP API and implementation. You can build you own from the source, or you can grab the latest binaries.

Solaris ships with native support for SCTP since Soalris 10. So if you are running on Solaris 10 or greater, then once you got a JDK with SCTP you are good to go.

On Linux it is preferred to run a recent 2.6 kernel with SCTP support (most kernels in the main distros have this by default). Additionally, you will need to get the LKSCTP package that provides user level access to additional SCTP specific functionality. Example:

Fedora 10: sudo yum install lksctp-tools-1.0.9-1.fc10 or

Ubuntu: sudo apt-get install lksctp-tools

Running a simple SCTP application

To ensure that you have a correctly configured machine and JDK, try compiling and running the following application:

public class TestSCTP
{
public static void main(String[] args) throws Exception {
com.sun.nio.sctp.SctpChannel sc = com.sun.nio.sctp.SctpChannel.open();
}
}

$ jdk1.7.0/bin/javac TestSCTP.java
$ jdk1.7.0/bin/java TestSCTP


If it compiles and runs without any errors, then congratulations you have a correctly configured machine and JDK. You can now start writing applications that use the SCTP API.

Communicating over SCTP in Java

SCTP - Stream Control Transmission Protocol is a relatively new (standardize in year 200 by IETF) transport layer protocol to design to operate over IP. It is an alternative for TCP and UDP and combines many good features of those protocols. Main intention of developing SCTP was to cater the growing demand of IP telephony market.

Since SCTP is relatively new protocol programming language support for this is also not as commonly available as TCP or UDP, especially you are Java developer. But is you are a C/C++ developer then you have no problem, there is a very good guide on UNIX - Network Programing Vol1-3rd Edition (chapter 9, 10 and 23).

If you are Java developer then you'd have to use OpenJDK instead of Sun java JDK, since at present only OpenJDK has the support for SCTP. So first thing you have do is to download and install OpenJDK-7. Currently it only has versions for Linux and Solaris, again if you are using Windows then you'll have to do some more research. I've tried this only on Linux(Fedora), may be later I'll try with Windows as well. If your Linux kernel do not support SCTP, then you'll have install LKSCTP as well. Here is the small getting started guide at OpenJDK site. You can use the small test program given that guide to test whether your SCTP stack if working properly. I'll post small client-server program in SCTP in a later post.

PS: I found this SCTP library for Windows http://www.sctp.be/sctplib/, but couldn't check whether there is a support from OpenJDK-SCTP side for windows. If you find something please let me know as well.