Java EE 7 SDK 

Samples Main Page

The Echo WebSocket Sample Application

This sample is a Hello world application using the Java API for WebSocket.

Description

This sample shows how to use the annotations in the Java API for WebSocket (JSR 356) to create a simple WebSocket endpoint. The class EchoEndpoint is a very simple endpoint: it sends back every incoming text message. You can access the endpoint from the index.html page included in this sample. This page contains a very simple JavaScript client that sends the contents of a text field to the server and shows the response on the page.

Key Features

This sample demonstrates the following key features:

Building, Deploying, and Running the Application

Perform the following steps to build, deploy, and run the application:

  1. Set up your build environment and configure the application server with which the build system has to work by following the common build instructions.
  2. app_dir is the sample application base directory: samples_install_dir/javaee7/websocket/echo.
  3. Build, deploy, and run the sample application using the run outcome.

    mvn clean verify cargo:run

  4. Front page of this sample is at http://localhost:8080/websocket-echo.
    (The port number might vary.)
  5. Use the clean outcome to undeploy the sample application and to remove the temporary directories such as build and dist.

    mvn clean

Troubleshooting

If you have problems when running the application, refer to the troubleshooting document.



Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved.