Skip to content

Latest commit

 

History

History
63 lines (37 loc) · 2.64 KB

README.md

File metadata and controls

63 lines (37 loc) · 2.64 KB

Overview

Sample of using a WebSocket client within a JavaFX client application.

The project makes use of the Tyrus WebSocket framework.

Description

Creates a scene where the user can input their name, then submit a request to a WebSocket server, which will respond with Hello <name>, the output of which is recorded in a label on the scene.

As this is built to be a self-contained demonstration application, a local WebSocket server is started when the application starts up and the local server is shutdown when the application is stopped.

Implementation Notes

  1. Websocket communication occurs within an asynchronously executed JavaFX Task.

  2. WebSocket endpoints are defined as annotated endpoints as documented in the specification for JSR-356: Java API for WebSockets.

  3. A new server connection is created for each communication task (i.e. connection resources are not shared or reused between tasks).

  4. This implementation is not proxy aware. For information on making the system proxy aware see the Tyrus proxy documentation.

  5. For high traffic communication it would be recommended to use a different implementation which reuses such resources, for example:

Sample Screenshot

image

Build Requirements

This project requires Oracle Java 8u20+ and Maven 3.2.3+.

Checkout

git clone https://github.com/jewelsea/javafx-websocket-test.git

Build

mvn com.zenjava:javafx-maven-plugin:8.1.2:web

Execution

To run the resultant application as a standalone jar:

java -jar target/jfx/app/javafx-websocket-test-jfx.jar

To run the resultant application as webstart app:

javaws target/jfx/web/javafx-websocket-test.jnlp

Attribution

This is a JavaFX Maven Plugin built project. Information on using the JavaFX Maven Plugin is at:

A skeleton for this project was generated using the JavaFX Maven Plugin Quickstart Archetype, then significantly modified after that.