Chat Demo with WebSockets

This is a trivial demo with Tyrus how WebSockets could be implemented for a messaging application.

How to run:

Java: mvn clean install && java -jar target/websocket-chat-demo-0.0.1-SNAPSHOT.jar

Frontend: Open index.html in 1 or more tabs.

Resources

This example is from:

Other examples:

Summary

WebSockets use HTTP to upgrade to the websocket protocol. So there has to be a http handshake before the websocket protocol will be used.

These are the links I used to learn about WebSockets:

These are all Java implementations of WebSockets. There is also Jetty, Undertow, Tomcat implementations. Spring has an entire starter-pom for WebSockets. There is also a JSR 356, Java API for WebSocket. TooTallNate doesn't implement it I guess.

Note:

Please don't try to implement WebSockets by yourself. Use an existing implementation like Tyrus or Tomcat Websockets.