| By Jonas Jacobi | Article Rating: |
|
| August 13, 2012 06:00 AM EDT | Reads: |
5,227 |
This tutorial series walks you through the simple steps of building an HTML5 WebSocket app, demonstrating the power of the publish/subscribe development pattern directly in JavaScript. Our sample is almost as simple as a Chat app, the “Hello World” app of the WebSocket world, but is a tad more visual and dynamic.
After trying out the completed application, you can either jump in the code and play with it right away, or move on to Part 2 (coming soon) of this tutorial for a step-by-step guide.
About the Environment
This tutorial requires a WebSocket server. We will use http://tutorial.kaazing.com, which hosts the JMS Edition of Kaazing WebSocket Gateway, Kaazing’s high-performance enterprise-grade WebSocket Server. All you’ll need to do is create a WebSocket connection to this server directly from your browser and start “talking” (read: send messages) to it from your browser. On the client side, you can use any modern browser, supported by JSFiddle (learn more about JSFiddle).
Getting Started
First, to understand how the tutorial environment in JSFiddle works, open up the completed demo in JSFiddle. If you’re using a tablet or a smart phone, use the full page mode of the demo.
JSFiddle provides a simple, integrated environment to edit the source of your web pages and apps. It has four panes:
- Top-left: HTML code (very minimal HTML code in our demo)
- Bottom-left: JavaScript code
- Top-right: CSS code (empty in our case)
- Bottom-right: Result
In the bottom right pane, you can interact with the completed app. Using the slider, you can change the size of the image. Now, open another browser window, pointing to the same JSFiddle demo URL. You can also use a tablet or a smart phone. Position your two browser windows side-by-side. As you adjust the slider in the bottom-right pane, right above the image in one browser window, the slider position and image size change in the other one. They’re kept in sync.
The browsers are communicating with the WebSocket gateway which is running in Amazon’s EC2 cloud, hosted in North Virginia, USA. When you move the slider, messages travel from your browser, to the WebSocket gateway, and back to the other browser.
Watch this video demonstrating the completed application (if the letters are blurry, switching the video to HD helps):
At this point, you can make any changes to the application. Click the Run button to test out your changes. To roll back to the original state, simply reload the original JSFiddle demo URL.
Note: If you see the image resize without you moving the slider, there’s a chance that somebody else is experimenting with the tutorial as well. To ensure that you’re not interfering with anybody else, change the topic name to something unique to you, for example by appending your name. Locate the following line in the bottom-left pane, towards the top of the file:
var TOPIC_NAME = "/topic/myTopic";
Modify the name of the topic. For example:
var TOPIC_NAME = "/topic/PeterTopic";
Test your code by clicking the Run button.
As another test, you can also change the application’s logging behavior. To give it a try, change the value of the IN_DEBUG_MODE variable to false, located in the bottom-left pane towards the top of the file. Original line:
var IN_DEBUG_MODE = true;
After the changes:
var IN_DEBUG_MODE = false;
Test your code by clicking the Run button.
In Part 2 (coming soon) you can learn about the demo code and how quickly and easily you can build real-time web applications with Web messaging.
Read the original blog entry...
Published August 13, 2012 Reads 5,227
Copyright © 2012 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Jonas Jacobi
Jonas Jacobi is President and CEO of Kaazing, a privately held company that delivers next generation high-performance Web communication platform providing distribution of live data to the online financial trading, betting, gaming, auction, social, and media industries. Before co-founding Kaazing Jonas served as VP of Product Management for Brane Corporation, a leader in platform and technology independent solutions for any type of application software technology, automating the entire application development process required to maximize the business value of software. Prior to Brane Corporation, he spent over 8 years at Oracle where he served as a Java EE and open source Evangelist, and product manager responsible for the product management of JavaServer Faces, Oracle ADF Faces, and Oracle ADF Faces Rich Client in the Oracle Application Server division. Jonas is a frequent speaker at international conferences and has written numerous articles for leading IT magazines such as Java Developer's Journal, JavaPro, AjaxWorld, and Oracle Magazine. Mr. Jacobi is co-author of the best-selling book Pro JSF and Ajax: Building Rich Internet Components, (Apress).
- Cloud People: A Who's Who of Cloud Computing
- Cloud Expo New York: Delivering Digital Marketing on the Cloud
- AWS Going into a New Line of Work
- Session Topics: 12th Cloud Expo / Cloud Expo New York
- Five Big Data Features in SQL Server
- How Bon-Ton Stores Align Business Goals with IT Requirements
- Cloud Conversations: AWS EBS, Glacier and S3 Overview | Part 2 S3
- Amazon Cuts Prices on S3
- Cloud Conversations: AWS EBS, Glacier and S3 Overview | Part 3
- Compuware Signs New APM Partnership
- Google Submits Concessions to EC; Gets Sued in the UK
- Component Models in Java | Part 1
- Cloud People: A Who's Who of Cloud Computing
- Software Defined Networking – A Paradigm Shift
- Cloud Expo New York: Delivering Digital Marketing on the Cloud
- AWS Going into a New Line of Work
- Session Topics: 12th Cloud Expo / Cloud Expo New York
- Help Desk Solution Empowers Employees
- Five Steps Toward Achieving Better Compliance with Identity Analytics
- Five Big Data Features in SQL Server
- Development Testing for Java Applications
- Big Data Is Not Just About Marketing: Don’t Forget the IT Department’s Needs
- How Bon-Ton Stores Align Business Goals with IT Requirements
- A Cloud-Based Testing Tool for the Budget-Minded
- Where Are RIA Technologies Headed in 2008?
- Processing XML with C# and .NET
- AJAX World RIA Conference & Expo Kicks Off in New York City
- JSON vs XML - A Jason vs Freddie Sequel
- The Top 250 Players in the Cloud Computing Ecosystem
- Has the Technology Bounceback Begun?
- BPEL Processes and Human Workflow
- i-Technology Viewpoint: The Very Confused World of 3D and XML
- Generating XML from Relational Database Tables
- "HP's Problem Ain't the SAP Install," Says Sun's Schwartz
- Open Source Database Special Feature: An Introduction to Berkeley DB XML
- eXist - An Introduction To Open Source Native XML Database

























