Skip to content

OpenLiberty/sample-sse-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SseChat Sample

A simple chat room using JAX-RS 2.1 Server Sent Events (SSE)

This sample is intended to help understand how to write SSE applications that broadcast events to multiple clients. In this sample, a remote client would register (GET) with the ChatResource - this establishes an SSE connection - and then clients could send (PUT) a message. The ChatResource would then broadcast that message to all registered clients.

To run this sample, first download or clone this repo - to clone:

git clone [email protected]:OpenLiberty/sample-sse-chat.git

From inside the sample-sse-chat directory, build and start the application in Open Liberty with the following command:

mvn clean package liberty:run-server

The server will listen on port 9080 by default. You can change the port (for example, to port 9081) by adding mvn clean package liberty:run-server -DtestServerHttpPort=9081 to the end of the Maven command.

After the server has started, you should see some output like this:

At this point, you can enter the following URL into your browser:

http://localhost:9080/SseChatSample/index.html

I recommend connecting with multiple browsers, so that you can have a conversation like this one:

Note that SSEs do not work in all browsers. Consult Wikipedia for more information on browsers that support SSEs.

Press Ctrl-C from the command line to stop the server.

Please take a look at the source code that makes this possible. If you run into any problems with the sample, please let us know by opening a new issue.

Thanks!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published