JavaFBP Support for WebSockets
This project comprises some components which support WebSockets for JavaFBP, plus a test case to illustrate their use. The components are basically @tootallnate's AutobahnServerTest code - see https://github.com/TooTallNate/Java-WebSocket - split into two JavaFBP components:
Promoted to Maven, July 12, 2017. To locate, do http://search.maven.org/#search%7Cga%7C1%7Cjavafbp-websockets .
For video on interactive systems, with demo of JavaFBP-WebSockets, click on https://youtu.be/IvTAexROKSA .
For more background information on JavaFBP, see the README on https://github.com/jpaulm/javafbp .
Web site for FBP:
JavaFBP Syntax and Component API:
This project requires JavaFBP and Java-WebSocket to execute. Recent jar files for these projects will be zipped into the JavaFBP-WebSockets jar file, and will also be in the
It also requires Gradle for (re)building (tested with version 2.0). You can download the corresponding package from the following URL: http://www.gradle.org
Eclipse IDE Integration
You can generate Eclipse project using the following mvn command:
If you already created an Eclipse project you can run:
gradle cleanEclipse Eclipse
You need to install a Gradle plugin for Eclipse as explained here:
Then import a generated project in Eclipse, right (ctrl for OSX) click on the project in Eclipse -> Configure -> Convert to Gradle Project. After the conversion you can Right (ctrl for OSX) click on the project -> Gradle -> Task Quick Launcher and type
You should also make sure that the current Java JDK
tools.jar file is in your project's
Building project from command line
git init to create the
git clone https://github.com/jpaulm/javafbp-websockets.git
gradle build in your JavaFBP-WebSockets directory - this will create a
javafbp-websockets-1.2.2.jar file in the
build/libs directory - this also contains a test network, called
TestWebSockets.java, the various files from the two jar files listed in
build.gradle as dependencies, and a couple of "chat" HTML5 scripts. This only has to be done once.
Running a test
This project has one test network, which runs as a server, communicating with the client, which is
chat2.html. This test can either be run under Eclipse, or can be run from the command line.
Two HTML5 scripts are provided to allow the software to be tested using multiple concurrent users.
Note: if your default browser gives you a message saying it does not support Websockets, try using Chrome.
You can run the command-line test Server code in com.jpmorrsn.fbp.websockets.networks.TestWebSockets by entering in the project directory
java -cp "build/libs/javafbp-websockets-1.2.2.jar" com.jpaulmorrison.fbp.examples.networks.TestWebSockets
(note the double quotes).
In *nix, replace the ; with :.
This will display the message
WebSocketServer starting on the console.
There are two simple, almost identical, client HTML5 scripts called
src/main/resources/scripts, which support two commands:
complistwill display the contents of any selected jar file (specified in the
namelistwhich just outputs 3 names.
If you do not see
chat2.html in the Navigator view, click on
Link with Editor in the Navigator tool bar.
To run the test:
chat2with your favorite web browser
complistin the field prefixed with
- enter the file name of any jar file whose contents you wish to display, in the field prefixed with
- click on
You should see all the entries in the selected jar file.
namelist in the
Command field, which will show three names on the user screen.
To run or rebuild the project under Eclipse, you will need to add the JavaFBP and Java-WebSocket jar files in the
lib directory to the
Properties/Java Build Path/Libraries using the
Add JARs function.
To rebuild the project under Eclipse, you will also need to add
tools.jar from your current Java JDK.
You may have to do a trivial edit (e.g. add a blank) to the
chat2.html files after downloading them - see https://github.com/jpaulm/javafbp-websockets/issues/4 .
Closing down your test
Go back to the input form, and click on
Stop WS, and the server should come down, terminating the Web Server.
At the end of the run, you should see:
Run complete. Time: x.xxx seconds Counts: C: 586, D: 588, S: 589, R (non-null): 592, DO: 0 or something similar)
where the counts are respectively: creates, normal drops, sends, non-null receives, and drops done by "drop oldest".
Here is a diagram of this simple server network, together with the client, shown schematically:
The test application has now been modified to add a (substream-sensitive) Load Balancer process, and the Process and WebSocketRespond processes have been multiplexed. The result looks like this:
Note that LoadBalance in JavaFBP has been updated to be sensitive to substreams - see https://github.com/jpaulm/javafbp/blob/master/src/main/java/com/jpaulmorrison/fbp/core/components/routing/LoadBalance.java .