# Stomp WebSockets Example

This example shows you how to configure HornetQ to send and receive Stomp messages from modern web browser using Web Sockets.

At the moment, WebKit and Google Chrome are the only web browsers with Web Sockets support.

## Example Setup

The example will start a HornetQ server configured with Stomp over Web Sockets and JMS. Web browsers clients and Java application will exchange message using a JMS Topic.

To enable Stomp over Web Sockets, the server must have a NettyAcceptor configured with a protocol parameter set to stomp_ws:

    <acceptor name="stomp-websocket">
       <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
       <param key="protocol" value="stomp_ws"/>
       <param key="port" value="61614"/>
    </acceptor>

## Example step-by-step

To run the example, you need to start HornetQ server from the `bin` directory and specify this example's server configuration:

    $ ./run.sh ../examples/jms/stomp-websockets/server0
    ...
    [main] 17:45:03,498 INFO [org.hornetq.core.remoting.impl.netty.NettyAcceptor]  Started Netty Acceptor version 3.2.0.BETA1-r2215 localhost:61614 for STOMP_WS protocol
    [main] 17:45:03,505 INFO [org.hornetq.core.server.impl.HornetQServerImpl]  HornetQ Server version 2.1.0.CR1 (Hungry Hornet, 117) started

To publish a message to a JMS topic from a Java application, simply type `./build.sh` (or `build.bat` on windows) from this directory:

    $ ./build.sh
    ...
    [java] Sent message: message sent from a Java application at Wed Apr 28 17:45:53 CEST 2010
    [java] Received message: message sent from a Java application at Wed Apr 28 17:45:53 CEST 2010
    [java] example complete
    [java]
    [java] #####################
    [java] ###    SUCCESS!   ###
    [java] #####################

To subscribe to the topic from your web browser, open the Chat Example from another tab. The chat example is preconfigured to connect to the HornetQ server with the URL `ws://localhost:61614/stomp` and subscribe to the JMS Topic (through its core address `jms.topic.chat`).

You can open as many Web clients as you want and they will all exchange messages through the topic

If you run again the Java application (with `./build.sh`), the web clients will also receive its message

## Documentation

A JavaScript library is used on the browser side to be able to use Stomp Over Web Sockets (please see its documentation for a complete description).