Skip to main content
Getting Started with the Web Sockets SDK
Danny Coward, December 2011

Before you read this, please be sure you have read the Introduction to the Web Sockets SDK.

Outline

Once you have done everything on this page successfully, you will have set up the SDK, compiled and run the sample applications. The Echo sample, for example, is a simple Web Socket application with one end point and a client. The end point is a POJO decorated with the Web Socket annotations that are part of the Web Socket SDK API that replies to messages it receives synchronously. The client is a web page that contains some JavaScript code that contacts the end point using the native support for web sockets in your browser (Chrome, Safari...), and displays the returning message. Once you have that up and running, you'll have a pretty good idea how to use the SDK to run some of the more complicated samples, and even to start writing some of your own !

Running the Echo Sample

System Requirements
  • JDK 1.6+
  • Glassfish 3.1.2
  • NetBeans 7.something (not totally necessary, see notes)
  • a Web Socket enabled browser. e.g. latest Safari, Chrome.
Notes

It's really simplest if you do all this in NetBeans 7.0.1 because that's what I use, and all the project dependencies you'll need are already in the repository, so I know it works. But I'll write these instructions so that you should be able to work out how to get started if you are not using NetBeans.
You don't have to have all of Glassfish 3.1.2 if you only want to run the Echo sample: if you don't want it all, then you will need to get Grizzly 1.9.46 yourself. And you'll need something that can run a simple JSP. And the servlet API v3.0 JAR. If you want to run the web integration applications - like the Trading Console, you'll will need Glassfish however.

Check out and build the Web Sockets SDK

Check out the following projects:-

<repo>/SDK/WS_API/*
<repo>/SDK/WS_Platform_1946/*

You'll have to resolve a couple classpath dependencies.
First the WS_API project depends on the servlet api. You'll find this in your glassfish installation directory <Glassfish>/glassfish/modules/javax-servletapi.jar. Now build the project.
Second, the WS_Platform_1946 project depends on the WS_API JAR which you just built, so resolve that. It also depends on the servlet api, so resolve that. It also depends on Grizzly. That dependency you can resolve by adding all the JAR files in <Glassfish>/glassfish/modules that begin either with grizzly* or gms* - 14 JARs in total. Now build that project.

If everything has worked so far, you have built yourself a copy of the Web Sockets SDK !

Check out, build and run the Sample Apps

Check out the samples:-

<repo>/Samples/WSClientSamplePages/*
<repo>/Samples/WSSampleBeans/*

The WSSamplePages application only contains JSPs and JavaScript and doesn't depend on anything else, so you're good to go there.
The WSSampleBeans application has a few dependencies you'll need to resolve. First, it uses a JSON API for parsing in the drawing sample. So you'll need to go build the JAR from http://json.org/java/ for that. Also it depends on the WS_API and WS_Platform JARs you built earlier.

Now you are nearly there. The very last thing you need to do is to tell the whatever is compiling the samples for you to use the annotation processor when it encounters Web Sockets annotations in the sample code. In NetBeans, go to the project properties dialog, select Build->Compiling. Check the boxes to enable annotation processing, and enable annotation processing in the editor, turn off Compile on Save, and add websockets.platform.processors.WSProcessor to the list of annotation processors.

Now you are good to go ! Run the WSSampleBeans project in NetBeans. You'll see it has some sensible choices for hostname and port in the Run command. Without NetBeans, you will be doing something like this:

java application.Main localhost 8021 /websockets/samples application.ChatServer;application.EchoBean;application.SimpleLifeBean;application.GroupDrawServer

Remember, if you chance the hostname and port, you'll need to update the WSClientSample code too. Then deploy the sample pages to Glassfish (or wherever) and you should be able to try all the samples !

Extra Credit: Running the SDK in Web Integration Mode


















 
 
Close
loading
Please Confirm
Close