jWebSocket Step-By-Step – Part 1

This is the first part of the series of articles that i will write to cover the basics of jWebSocket Project, so that the users or developers can download the project and start using it either with the default features that comes with jWebSocket or with customized functionality on top of jWebSocket platform. Project jWebSocket is an open source Java and JavaScript implementation of the HTML 5 WebSocket protocol with a huge set of extensions. You can find more details about the architecture and different server concepts on our site http://jwebsocket.org. The aim of this article is to focus more on how to use it and get started and understand the various nitty gritty of jWebSocket usage.

So, how do i set it up quickly and run it?? Well, if you cannot wait at all then we have few demos in our product site that you can try without even bothering to set it up in your machine. But, if you want to try the thick and thing here are steps to follow:

Download the latest zip file jWebSocketServer-0.9.0.zip from here for the server and jWebSocketClient-0.9.0.zip from here. After you download and extract it you will see the folder structure like this.
jWebSocket Folder Structure
As you can see there are basically 4 folders
  • bin  - contains the batch file to run the server
  • conf – contains the configuration file ‘jWebSocket.xml‘, I will discuss more about it later.
  • libs – this folder contains all the jar files of different modules in jWebSocket, bundle jar and war for web application.
  • logs – folder that contains log settings.
Similarly for client, you will see the demos html file and javascript files. Now we have two options or modes to run jWebSocket

1. Standalone Server - Whichever mode you want to use, first set the environment variable JWEBSOCKET_HOME to the base location of your jWebSocket-0.9.0 folder(eg: /Users/puran/jWebSocket-0.9.0). To run as stand alone server, simply execute the batch/script file  from the bin directory of the jWebSocket folder. If every thing is honky dory your stand alone server should start successfully at port 8787. My Console looks something like this.

Now to test our stand alone jWebSocket server open any of the demo html files from jWebSocketClient-0.9.0 package you downloaded above. For example if I open file like file:///Users/puran/projects/jwebsockets/jWebSocket/jWebSocketClient-0.9.0/demos/chat/chat.htm then you should be able to login to the chat window as shown below.

2. jWebSocket embedded in Web Application – This option allows you to run jWebSocket Server as an web application in your Tomcat server so that it’s easier to integrate with other web applications.To do this simply copy the jWebSocketAppSrvDemo-0.9.0.war file from JWEBSOCKET_HOME/libs folder to the webapp folder of your tomcat installation. Now copy the jar file jWebSocketServer-Bundle-0.9.0.jar from the same libs folder to the lib folder of your tomcat. This single bundle jar bundles all the required libraries to run jWebSocket. Now at this moment we will not change any configuration whatsoever and just run with the default settings and configuration. Start your tomcat server and point your browser to http://localhost:8080/jWebSocketAppSrvDemo-0.9.0/. If everything is setup properly then you should see the home page with few demos.
So in this very first part we tried to get a quickstart run of jWebSocket. In the second part which will write shortly we will try to understand little bit more about our javascript client library and write our own simple client application that uses the default functionality of jWebSocket server. I hope all of you will find this article helpful in understanding very basics of jWebSocket. Please feel free to send feedbacks or any comments you have in mind.