Kaazing at SFHTML5: All about WebGL

Kaazing was invited to speak at the upcoming San Francisco HTML5 User Group meeting on January 23, 2014 at Google’s San Francisco office. The title of the event is All about WebGL. I (Peter Moskovits) am representing Kaazing, sharing a speaking slot with Victor Sand from Goo Technologies. If you cannot make it to the event in person, the event is televised live streamed on Google Developers Live.

victorsand
Victor Sand – Goo Technologies

To get an idea what our talk is about, here’s an excerpt from our abstract:

Victor and Peter will demonstrate how WebGL experiences created with Goo Engine can be elevated to the next level by making them even more immersive and engaging. They will show how you can use any smartphone connected to the public Internet to remotely control WebGL applications and games. Last, Peter and team will demonstrate how this communication pattern can be applied to control Web connected physical objects from continents away.

As Vanessa Wang, co-organizer of the meetup, who not by the way runs documentation at Kaazing, stated in her meetup invitation:

One of the highlights of this event is a deep dive talk from a technical expert from Sony Entertainment Network/Playstation 4 on how the Playstation 4 UX was built with WebGL. This talk is part of a jam-packed technology event centered on WebGL, starting with a high-level introduction to WebGL, WebGL and Playstation UX, WebGL and Real-Time Communication, and finally a comprehensive talk on developing with WebGL, LEAP Motion, Three.js, WebRTC, and the Web Audio API.

If you’re at the event, remember to stop by the Kaazing table. If for nothing else, to drop your business card, as at the event we’ll be raffling off an iPad Mini Retina.

display_hero

Posted in html5, Kaazing, Uncategorized, WebSocket | Tagged | Leave a comment

Kaazing Powers the Internet of Things at HTML5DevConf October 2013 (San Francisco)

On 21-24 October 2013, HTML5DevConf returned to San Francisco, this time at the enormous Moscone Center North. As always, the sold-out conference attracted web developers, architects, business development leads, CTOs, CEOs, designers, students, QA engineers, technical writers — and many more — from all over the world. With the move from the Palace Hotel to Moscone North, the conference also saw a huge increase in attendance with filled rooms for all ten (yes, 10) tracks. The conference also held three days of training, all of which sold out weeks before the event.
HTML5DevConf logo
Kaazing was proud to host a booth on both days of the conference in Moscone’s famous Exhibit Hall. We showed lots of demos of using WebSockets and HTML5 to power objects (including a radio controlled truck), super-fast financial applications, as well as controlling Goo Technologies’ Pearl Boy demo with WebSockets. Here is one of our engineers, Sanjay, with the Android mascot …
sanjay-android-intel
… and our booth in the Exhibit Hall.
kaazing-booth
It was a fun event, and we even raffled off an iPad mini. Congratulations to the winner, Steve!
iPad mini winner
Our own Head of Training, Richard Clark (@rdclark), led a day-long training course on Native HTML5 Development. Kaazing’s Director of Technology, Frank Greco (@frankgreco) and Director of Product Management, Robin Zimmerman (@robinzim) gave a presentation to hundreds of attendees on WebSocket Perspectives and Visions for the Future. Frank’s slides are online; the recording will be available soon. Frank and Robin also showed some cool demos on using WebSockets and messaging (pub/sub) with a Raspberry Pi to control objects, including turning on a light using a light switch remotely over WebSockets. This demo was built by Kaazing engineers David Witherspoon (@DPW_Spoon) and Prashant Khanal (@ipras); check out how they built it.
frank-robin-demosfrank-robin-crowd
After Frank and Robin’s presentation, we returned to our booth and enjoyed more conversation with attendees on using messaging and WebSockets.
robin-boothfrank-booth
This was a really exciting and fun conference. Thanks so much to Ann and her awesome team of organizers. We’re definitely looking forward to the next one!

Posted in html5, training, Uncategorized, WebSocket | Tagged , , , , , , , | Leave a comment

Controlling Physical Devices on the Real Time Web: Kaazing IoT Talk at JavaOne 2013

Two visionary Kaazing engineers, David Witherspoon and Prashant Khanal, gave an exciting presentation at JavaOne this year: JMS, WebSocket, and the Internet of Things — Controlling Physical Devices on the Real Time Web.

DSC_1196

David and Prashant led the audience through the steps of building connected Things by combining open source hardware, a Raspberry Pi, with real-time Web communication and messaging, powered by Kaazing.

They started off by demonstrating Kaazing’s remote controlled truck. A remote member of the team joined the presentation over Skype and used a Web browser on his smart phone to control the truck in the conference room.

IMG_6014

Next, they walked the audience through building similar M2M systems. David and Prashant used the simplest “machines” for their demonstrations: a light bulb and a switch, each connected to a Raspberry Pi. All it took was three basic steps.

DSC_1197

1. Connecting Hardware with Software – the Magic of the Raspberry Pi

The software stack installed on the two Raspberry Pis:

This step consisted of two sub-steps. First, Prashant and David demonstrated how to leverage software running on the Pi to turn the light on/off. Then, they showed how the Raspberry Pi can detect the on/off state changes of the switch. It’s important to note that in this step, a switch was connected to a Pi and a lightbulb was connected to another Pi; the switch and the lightbulb (the two Things) are not yet connected.

Watch David demonstrate how software controls the two hardware pieces, the light and the switch.

Source Code for the Light

light

package com.kaaazing.demo.light;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;

public class Light {

	private final GpioController gpio;
	private final GpioPinDigitalOutput gpioPin;

	public Light() {
		gpio = GpioFactory.getInstance();
		gpioPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01,
				"MyLight", PinState.LOW);
	}

	public void on() {
		gpioPin.high();
		System.out.println("Light on");
	}

	public void off() {
		gpioPin.low();
		System.out.println("Light off");
	}

	public void shutdown() {
		gpio.shutdown();
	}

	public static void main(String[] args) {
		Light lightController = new Light();
		System.out.println("Light controller initialized");
		try {
			Thread.sleep(2000);
			lightController.on();
			Thread.sleep(2000);
			lightController.off();
			Thread.sleep(2000);
			lightController.on();
			Thread.sleep(2000);
			lightController.off();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			lightController.shutdown();
		}
	}

}

First, in lines 16-17 a General Purpose I/O (GPIO) output pin is initialized. Then, in the on() and off() methods we set its value to high (line 21) and low (line 26). Eventually, we invoke the on() and off() methods.

Note: For the entire source code, scroll to the bottom of this post.

Source Code for the Switch

switch

package com.kaaazing.demo.toggle;

import java.util.concurrent.CopyOnWriteArrayList;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;

public class Toggle {
	private final GpioController gpio;
	private final GpioPinDigitalInput gpioPin;
	private final CopyOnWriteArrayList listeners;

	public Toggle() {
		listeners = new CopyOnWriteArrayList();

		gpio = GpioFactory.getInstance();
		gpioPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00,
				PinPullResistance.PULL_DOWN);
		gpioPin.addListener(new GpioPinListenerDigital() {

			@Override
			public void handleGpioPinDigitalStateChangeEvent(
					GpioPinDigitalStateChangeEvent event) {
				notifyListeners(event.getState());
			}
		});
	}

	private void notifyListeners(PinState state) {
		if (state == PinState.HIGH) {
			System.out.println("Toggle on");
		} else {
			System.out.println("Toggle off");
		}

		for (ToggleListener listener : listeners) {
			if (state == PinState.HIGH) {
				listener.on();
			} else {
				listener.off();
			}
		}
	}

	public void registerListener(ToggleListener listener) {
		listeners.add(listener);
		// send initial state
		if (gpioPin.getState() == PinState.HIGH) {
			listener.on();
		} else {
			listener.off();
		}
	}

	public void shutdown() {
		gpio.shutdown();
	}

	public static void main(String[] args) {
		Toggle toggle = new Toggle();
		System.out.println("Running toggle for 20 seconds");
		try {
			Thread.sleep(20000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			toggle.shutdown();
		}
		System.out.println("Exiting");
	}
}

 

package com.kaaazing.demo.toggle;

public interface ToggleListener {
	public void on();
	public void off();
}

For the switch, first we initialize an input pin, and then write the listener code waiting for the toggle event.

Note: For the entire source code, scroll to the bottom of this post.

2. Pub-Sub Messaging to Build a Loosely Coupled System – Introducing the Message Broker

Next, David and Prashant demonstrated how to connect the lightbulb and its Pi with the switch and its Pi. While it’s easy enough to connect the switch and the lightbulb directly, they wanted to show the power of the publish-subscribe (pub-sub) messaging model, which lets you build a real-life system. By using a pub-sub model, one Thing can send a message to another Thing via a message broker to send signals to each Thing. To illustrate this, David and Prashant used the open source Apache ActiveMQ JMS message broker that ships pre-packaged with the JMS Edition of Kaazing WebSocket Gateway, but you can use a variety of JMS message brokers to achieve the same result. Kaazing WebSocket Gateway integrates with a number of different JMS message brokers, including TIBCO Enterprise Message Service, Informatica Ultra Messaging, IBM WebSphere MQ, JBoss Messaging, Open MQ Messaging, and Oracle WebLogic JMS.

In this case, the Pi attached to the switch is the publisher, and the Pi attached to the light is the subscriber.

message-broker

Watch David demonstrate the connected scenario.

Source Code for the Light

package com.kaaazing.demo.light;

import java.net.URI;

import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;

import org.apache.activemq.ActiveMQConnectionFactory;

import com.kaaazing.demo.util.AbstractJmsMessenger;
import com.kaaazing.demo.util.DefaultExceptionListener;

public class LightJmsTcpController extends AbstractJmsMessenger {

    private final ActiveMQConnectionFactory connectionFactory;
    private final Connection connection;
    private final Session session;
    private final Topic topic;
    private final MessageConsumer consumer;
    private final Light light;
    private boolean running = true;

    public LightJmsTcpController() {
        try {
            light = new Light();

            connectionFactory = new ActiveMQConnectionFactory(URI.create("tcp://"
                    + BROKER_HOSTNAME + ":61616"));
            connection = connectionFactory.createConnection();
            connection.setExceptionListener(new DefaultExceptionListener());
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            topic = session.createTopic(LIGHT_TOPIC);
            consumer = session.createConsumer(topic);
            consumer.setMessageListener(new MessageListener() {

                @Override
                public void onMessage(Message message) {
                    try {
                        TextMessage textMessage = (TextMessage) message;
                        String messageData = textMessage.getText();
                        System.out.println("message received: " + messageData);
                        if (messageData.equals(ON_MESSAGE)) {
                            light.on();
                        } else if (messageData.equals(OFF_MESSAGE)) {
                            light.off();
                        } else if (messageData.equals(SHUTDOWN)) {
                            System.out.println("shutting down");
                            shutdown();
                        }
                    } catch (JMSException e) {
                        e.printStackTrace();
                        shutdown();
                    }
                }
            });

            connection.start();
            System.out.println("Light initialized");
        } catch (JMSException e) {
            shutdown();
            throw new RuntimeException(e.getMessage());
        }
    }

    private void shutdown() {
        running = false;
        if (light != null) {
            light.shutdown();
        }
        if (connection != null) {
            try {
                System.out.println("Cleaning up resources");
                connection.close();
            } catch (JMSException e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    }

    public static void main(String[] args) throws JMSException, InterruptedException {
        LightJmsTcpController lightController = new LightJmsTcpController();
        while (lightController.isRunning()) {
            Thread.sleep(1000);
        }
        System.out.println("Exiting Application");

    }

    public boolean isRunning() {
        return running;
    }

}

In this demo first we create an instance of the Light class (line 31), then a TCP connection to ActiveMQ (lines 33-35). Then, we create a JMS session (line 37), a topic (line 38), and a consumer (line 39), and define the message listener (line 40) that’s invoked when a new message arrives. Depending on the message, the light is turned on or off (lines 48-55).

Note: For the entire source code, scroll to the bottom of this post.

Source Code for the Switch

package com.kaaazing.demo.toggle;

import java.net.URI;

import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;

import org.apache.activemq.ActiveMQConnectionFactory;

import com.kaaazing.demo.util.AbstractJmsMessenger;
import com.kaaazing.demo.util.DefaultExceptionListener;

public class ToggleJmsTcpListener extends AbstractJmsMessenger implements
        ToggleListener {

    private final ActiveMQConnectionFactory connectionFactory;
    private final Connection connection;
    private final Session session;
    private final Topic topic;
    private final MessageProducer producer;
    private final Toggle toggle;
    private final MessageConsumer consumer;
    private boolean running = true;

    public ToggleJmsTcpListener() {

        try {
            toggle = new Toggle();

            connectionFactory = new ActiveMQConnectionFactory(URI.create("tcp://"
                    + BROKER_HOSTNAME + ":61616"));
            connection = connectionFactory.createConnection();
            connection.setExceptionListener(new DefaultExceptionListener());
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            topic = session.createTopic(LIGHT_TOPIC);
            producer = session.createProducer(topic);

            // clean shutdown listener
            consumer = session.createConsumer(topic);
            consumer.setMessageListener(new MessageListener() {
                @Override
                public void onMessage(Message message) {
                    try {
                        TextMessage textMessage = (TextMessage) message;
                        String messageData = textMessage.getText();
                        if (messageData.equals(SHUTDOWN)) {
                            System.out.println("shutting down");
                            shutdown();
                        }
                    } catch (JMSException e) {
                        e.printStackTrace();
                        shutdown();
                    }
                }
            });

            connection.start();
            System.out.println("Toggle initialized");
            toggle.registerListener(this);

        } catch (JMSException e) {
            shutdown();
            throw new RuntimeException(e.getMessage());
        }
    }

    @Override
    public void on() {
        try {
            System.out.println("Sending on message");
            producer.send(session.createTextMessage(ON_MESSAGE));
        } catch (JMSException e) {
            e.printStackTrace();
            shutdown();
        }
    }

    @Override
    public void off() {
        try {
            System.out.println("Sending off message");
            producer.send(session.createTextMessage(OFF_MESSAGE));
        } catch (JMSException e) {
            e.printStackTrace();
            shutdown();
        }
    }

    private void shutdown() {
        running = false;
        if (toggle != null) {
            toggle.shutdown();
        }
        if (connection != null) {
            try {
                System.out.println("Cleaning up resources");
                connection.close();
            } catch (JMSException e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    }

    public static void main(String[] args) throws JMSException,
            InterruptedException {
        ToggleJmsTcpListener toggleJmsTcpListener = new ToggleJmsTcpListener();
        while (toggleJmsTcpListener.isRunning()) {
            Thread.sleep(1000);
        }
        System.out.println("Exiting Application");
    }

    public boolean isRunning() {
        return running;
    }

}

Similar to the lightbulb, for the switch we create a TCP connection to ActivemMQ (line 37-39). After creating the JMS session (line 41), a topic (line 42), we create a JMS message producer (line 43). When the switch is toggled, we create and send a text message (lines 78 and 89) on the topic.

Note: For the entire source code, scroll to the bottom of this post.

3. Extending the Reach to the Web – WebSocket Transport with Kaazing WebSocket Gateway

The challenge with a TCP-based system, like the one outlined in Step 2, is that TCP has difficulty connecting isolated networks. To use TCP connections, you must open ports on firewalls and address the challenges of penetrating network intermediaries. Also, connectivity with mobile and Web applications raises issues. If you want to build a truly global system, you must ensure that your Things are always connected, no matter what.

The good news is that you can very easily extend your JMS-based applications to the Web, simply by introducing Kaazing WebSocket Gateway in the picture. With Kaazing, you can connect your devices in a secure fashion with low latency using open industry standard Web communication: HTML5 WebSocket.

WebSocket is a natural choice for asynchronous scenarios with event-driven architecture, such as the switch and the light. As the switch is toggled (event), the light (subscriber) is notified of the event asynchronously (without explicitly polling). It’s easy to see that using traditional synchronous Web programming models, like REST, don’t fit the bill as well as the asynchronous pattern that WebSocket supports.

For connected devices, reliability is critical. The moment a connection is lost due to network disruption or other errors, the Kaazing client will automatically try to restore that connection. The Kaazing client libraries will also re-subscribe to any active subscriptions prior to the connection failure.

In this demo, the switch and its Pi can be in Spokane, WA, while the light and its Pi can reside in Kathmandu, Nepal. As long as they’re connected to the public Internet, the JMS messages can traverse the Web, and the switch can control the light.

message-broker-kaazing

Watch David demonstrate the WebSocket connected scenario.

Source Code for the Light

package com.kaaazing.demo.light;

import java.net.URI;

import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;

import com.kaaazing.demo.util.AbstractJmsMessenger;
import com.kaaazing.demo.util.DefaultExceptionListener;
import com.kaazing.gateway.jms.client.stomp.StompConnectionFactory;

public class LightJmsWsController extends AbstractJmsMessenger {

	private final StompConnectionFactory connectionFactory;
	private final Connection connection;
	private final Session session;
	private final Topic topic;
	private final MessageConsumer consumer;
	private final Light light;
	private boolean running = true;

	public LightJmsWsController() {
		try {
			light = new Light();

			connectionFactory = new StompConnectionFactory(URI.create("ws://"
					+ GATEWAY_HOST + "/jms"));
			connection = connectionFactory.createConnection();
			connection.setExceptionListener(new DefaultExceptionListener());
			session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
			topic = session.createTopic(LIGHT_TOPIC_WS);
			consumer = session.createConsumer(topic);
			consumer.setMessageListener(new MessageListener() {

				@Override
				public void onMessage(Message message) {
					try {
						TextMessage textMessage = (TextMessage) message;
						String messageData = textMessage.getText();
						System.out.println("websocket message received: " + messageData);
						if (messageData.equals(ON_MESSAGE)) {
							light.on();
						} else if (messageData.equals(OFF_MESSAGE)) {
							light.off();
						} else if (messageData.equals(SHUTDOWN)) {
							System.out.println("shutting down");
							shutdown();
						}
					} catch (JMSException e) {
						e.printStackTrace();
						shutdown();
					}
				}
			});

			connection.start();
			System.out.println("Light initialized");
		} catch (JMSException e) {
			shutdown();
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		}
	}

	private void shutdown() {
		running = false;
		if (light != null) {
			light.shutdown();
		}
		if (connection != null) {
			try {
				System.out.println("Cleaning up resources");
				connection.close();
			} catch (JMSException e) {
				throw new RuntimeException(e.getMessage());
			}
		}
	}

	public static void main(String[] args) throws JMSException,
			InterruptedException {
		LightJmsWsController lightController = new LightJmsWsController();
		while (lightController.isRunning()) {
			Thread.sleep(1000);
		}
		System.out.println("Exiting Application");

	}

	public boolean isRunning() {
		return running;
	}

}

Notice that when switching from TCP to WebSocket, the only change you have to make to your code is replace the connection factory class, the protocol, and the port number.

Note: For the entire source code, scroll to the bottom of this post.

Source Code for the Switch

package com.kaaazing.demo.toggle;

import java.net.URI;

import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;

import com.kaaazing.demo.util.AbstractJmsMessenger;
import com.kaaazing.demo.util.DefaultExceptionListener;
import com.kaazing.gateway.jms.client.stomp.StompConnectionFactory;

public class ToggleJmsWsListener extends AbstractJmsMessenger implements
        ToggleListener {

    private final StompConnectionFactory connectionFactory;
    private final Connection connection;
    private final Session session;
    private final Topic topic;
    private final MessageProducer producer;
    private final Toggle toggle;
    private final MessageConsumer consumer;
    private boolean running = true;

    public ToggleJmsWsListener() {

        try {
            toggle = new Toggle();
			connectionFactory = new StompConnectionFactory(URI.create("ws://"
                    + GATEWAY_HOST + "/jms"));
            connection = connectionFactory.createConnection();
            connection.setExceptionListener(new DefaultExceptionListener());
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            topic = session.createTopic(LIGHT_TOPIC_WS);
            producer = session.createProducer(topic);

            // clean shutdown listener
            consumer = session.createConsumer(topic);
            consumer.setMessageListener(new MessageListener() {
                @Override
                public void onMessage(Message message) {
                    try {
                        TextMessage textMessage = (TextMessage) message;
                        String messageData = textMessage.getText();
                        if (messageData.equals(SHUTDOWN)) {
                            System.out.println("shutting down");
                            shutdown();
                        }
                    } catch (JMSException e) {
                        e.printStackTrace();
                        shutdown();
                    }
                }
            });

            connection.start();
            System.out.println("Toggle initialized");
            toggle.registerListener(this);

        } catch (JMSException e) {
            shutdown();
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }

    @Override
    public void on() {
        try {
            System.out.println("Sending websocket on message");
            producer.send(session.createTextMessage(ON_MESSAGE));
        } catch (JMSException e) {
            e.printStackTrace();
            shutdown();
        }
    }

    @Override
    public void off() {
        try {
            System.out.println("Sending websocket off message");
            producer.send(session.createTextMessage(OFF_MESSAGE));
        } catch (JMSException e) {
            e.printStackTrace();
            shutdown();
        }
    }

    private void shutdown() {
        running = false;
        if (toggle != null) {
            toggle.shutdown();
        }
        if (connection != null) {
            try {
                System.out.println("Cleaning up resources");
                connection.close();
            } catch (JMSException e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    }

    public static void main(String[] args) throws JMSException,
            InterruptedException {
        ToggleJmsWsListener toggleJmsWsListener = new ToggleJmsWsListener();
        while (toggleJmsWsListener.isRunning()) {
            Thread.sleep(1000);
        }
        System.out.println("Exiting Application");
    }

    public boolean isRunning() {
        return running;
    }

}

Interestingly, the source code used for the WebSocket-enabled scenario is almost identical to the one used in Step 2. As the highlighted code snippet indicates (lines 35-36), all you need to change is the connection information: simply modify the connection factory, the protocol, and the port number.

Note: For the entire source code, scroll to the bottom of this post.

To keep the audience engaged (and to emphasize the “color” of the WebSocket server used for the demos – Kaazing’s color is orange), for the WebSocket demo Prashant replaced the white light bulb with an orange one.

DSC_1202

Slides

You can also review the entire deck as presented at JavaOne.

Source Code & Download

The entire source code for the demonstration is published under David’s GitHub account. Star it, fork it, tweet it!

You can also download a free, fully functional version of the Kaazing WebSocket Gateway – JMS Edition that we used. To learn more, check out these resources:

Finally, you can meet David and Prashant in person and learn more about Kaazing and our platform at the upcoming HTML5DevConf (22-23 October at Moscone North in San Francisco, CA).

Tell us about your Raspberry Pi project – and drop a comment if you’re (interested in) building Internet (or Web) of Things applications.

Posted in Events, html5, JMS, Kaazing, WebSocket | Tagged , , , , , , | Leave a comment

Real Time Data Panel Discussion at Edge Conference 2013

At the Edge Conference in New York City last week a panel of 5 industry experts discussed some of the exciting questions and challenges of real time data. Here’s the abstract of the discussion:

WebSockets have now been with us for several years and enjoy near universal support. WebRTC is just starting out. Chat, live blogging, telemetry/dashboards, remote assist and video conferencing are all proven and popular use cases for real time data. Developers are becoming increasingly comfortable integrating real time elements into new projects, but problems remain with the complexity of scaling a real-time backend, as well as implementing APIs that are practical and useful.

john-fallowsBesides John Fallows, CTO and co-founder of Kaazing, Henrik Joreteg (&yet), Martyn Loughran (Pusher), Wesley Hales (Apigee), and Rob Hawkes (ViziCities) were invited to be on the panel, moderated by Scott Jenson (Jenson Design).

Here are a few deep links into interesting questions and topics addressed during the panel:

Question (14:26): WebSocket and other real-time protocols are commonly blocked by corporate proxies and content inspection firewalls; and that’s a particular problem for the sort of customers we have at the FT. How much is this stifling adoption and what do we do about it?

Question (22:42): Will the WebSocket protocol replace Server-Sent Events in the future? Why do we have to have both specs if WebSocket can accomplish the same tasks that SSE does, and more?

Question (35:30): We see a rise of security issues; people are trying to open too many TCP connections to a Web server and are killing the Web server as a result of it. Therefore, people tend to disable keep-alive connections to deal with this issue. What do you think about WebSocket security related to this problem and how can we solve it?

John on enabling the Web of Things (49:21)

Posted in Events, Kaazing, Security, WebSocket | Leave a comment

Kaazing Presentation at JavaZone

javazoneKaazing co-founder and CEO, Jonas Jacobi, gave a talk at JavaZone in Norway, titled 6 Years Later: One Line of Code That Changed the Web Forever. Jonas and his co-founder, John Fallows gave a presentation at JavaZone 5 years ago, and talked about the WebSocket standard the very first time in public.

In his talk, Jonas touches upon a number of interesting topics, including:

  • The challenges of HTTP
  • How the WebSocket standard addresses those challenges
  • The WebSocket protocol handshake and protocol
  • Protocol layering on top of WebSocket
  • Deployment topologies
  • Scalability
Posted in html5, JMS, Kaazing, Security, Uncategorized, WebSocket | Leave a comment

Kaazing CEO on Bloomberg TV

Kaazing co-founder and CEO, Jonas Jacobi, gave a live interview on Bloomberg TV today. Jonas discusses how the Web is transforming from static document sharing to an interactive, living experience.

KaazingBloombergTV

You can watch the 4-minute interview below.

Posted in html5, Kaazing, WebSocket | Leave a comment

WebSocket, Big Data, and Non-Blocking Server-Side I/O with Kaazing, MongoDB, and Node.js

In this example, we look at how real-time Web communications can work well with a non-blocking JavaScript back-end server and a NoSQL database. Our demo is a simple drawing app. If all you use is WebSocket with simple pub-sub messaging, you can already achieve pretty amazing things with drawing. For example, you can share a drawing board among multiple browser clients and while viewing each other’s drawings in real time.

Screen Shot 2013-06-03 at 12.05.19 PM

If you add a server-side component to it, you can do some central coordination and processing. And if on top of that you use a persistent storage, you can record all your real-time interactions to the database, and if needed play it all back. Icing on the cake is the ability of setting the replay speed: speeding it up or slowing it down.

Here’s what we did:

Read on to see how we did it.

The Architecture

Now let’s see how it’s all done.

The browsers connect to the Kaazing WebSocket Gateway. We use a higher level pub/sub API, JMS; this keeps our JavaScript code, running in the browser, simple. The JMS Edition of Kaazing comes out-of-the-box with an open source message broker, Apache ActiveMQ. The primary role of the message broker is to route the messages between the message publishers and the message subscribers. In addition to the browsers, we have Node.js as well connecting to the message broker. To achieve all this, we use a STOMP (Simple or Streaming Text Oriented Protocol) connector package for Node.js. By doing so Node.js will receive the same messages that the browsers receive. As the messages arrive to Node.js, they’re quickly passed on to MongoDB, which in turn will persist them. When the playback time comes, the messages are retrieved from MongoDB, and Node.js schedules and plays them back to the message broker, so they can be sent to the browsers for display.

Installing Kaazing and the Multi-Client WebSocket Drawing App

The simplest way of getting started is by installing the WebSocket app. To do so, you need to get a WebSocket server. You can download, install, and start a fully functional unlimited developer licensed Kaazing WebSocket Gateway in a few minutes. The simple steps are documented and shown here. Kaazing comes in various flavors (editions). As mentioned above, we use the JMS Edition, bundled with the open source Apache ActiveMQ JMS message broker, giving us the power of messaging on top of HTML5 WebSocket. Once you have the WebSocket server and the message broker up and running, all you need to do is copy the application code into a sub-directory: $GATEWAH_HOME/web/extras. We called ours draw. You can download the application from github.

Screen Shot 2013-06-04 at 9.51.28 AM

After starting up the Kaazing WebSocket Gateway, you’ll be able to access the application through the following URL:
http://YOUR_IP_ADDRESS:8001/draw
For example:
http://192.168.4.106:8001/draw

This will invoke the index.html file, pulling in the required JavaScript and CSS files from the /js and /css directories.

At this point, you have a collaborative mini drawing app. The app uses simple color coding: red is used to display drawing happening in this browser, and yellow is used when the drawing is originating from somewhere else, that is another browser window or played back from the database.

Installing MongoDB

mongodbThe next step is installing MongoDB, an open source NoSQL document database. It’s as simple as it gets, and is all documented here.

Installing Node.js

nodeThe last component is Node.js, an event-driven, non-blocking I/O server, allowing you to build data-intensive real-time apps in a lightweight manner. Node.js uses JavaScript on the server side.

The Application

Now, let’s walk through how the app was built.

HTML5 App in the Browser

The client-side HTML5 app consists of a couple of simple files: index.html, js/draw.js, and css/draw.css.

The HTML file renders the visible objects (canvas, button, and speed slider) on the page, the CSS file sets the visual attributes for them.

The draw.js file contains all the application logic. On the one hand it detects mouse gestures and takes care of the drawing, on the other hand it handles the communication with the message broker: it publishes messages when you’re drawing on the canvas, and consumes messages when somebody else is drawing or when a previously recorded drawing is played back from MongoDB and Node.js.

The browser can send two “types” of messages: control messages and drawing messages. Control messages are startRecordingstopRecordingplayBack, and deleteRecording.

If you’d like to learn more how you can use WebSocket with pub/sub messaging to build collaborative apps, this Tutorial is a great starting point.

Server-Side Code in Node.js

The app running in Node.js communicates with the message broker through STOMP. The server-side code is located in server.js. Before starting it, make sure you have Apache ActiveMQ running, as the server is attempting to connect to upon start. To start the server, simply run:

$>node server.js

After successfully connecting to it, the app will subscribe to drawTopic (/topic/drawTopic) that the browsers are publishing to. When the browser sends a control message, Node.js works hand-in-hand with MongoDB.

Recording

When recording, we save the coordinates of the pixels, along with the timestamp. Saving the timestamp will allow us to play back the recording in a properly timed manner (longer pauses in the drawing are recorded and played back as such).

Playing Back

The play-back functionality is done by Node.js querying the contents of the database (pixels to be drawn), and then scheduling the messages for publishing through the message broker. The messages will then eventually result in actual pixels drawn on the canvas(es) in the browser(s). We use the timestamp to set the delay between the messages.

Deleting the Recording

We can very easily delete the previous recording by deleting the collection from MongoDB.

More Information

  • Check out the project on github.
  • Try following the tutorial for building a simple peer-to-peer application yourself.
  • Learn more about Kaazing WebSocket Gateway – JMS Edition, which is a messaging over WebSocket solution using the Java Message Service API.
  • Check out the API documentation and other how-tos for building clients using Kaazing WebSocket Gateway – JMS Edition.
Posted in html5, JMS, Kaazing, WebSocket | 6 Comments