Once an initial connection has been opened the communication between the client and the server is bidirectional. This entails the server handling messages from clients and sending responses or broadcasting messages to connected clients. You canimplement the chat applications message handlers and other life-cycle event logic.
- [Instructor] Okay, so we're still…in the ChatServerEndpoint class,…and now we want to add logic…for the remaining life cycle methods.…So first, let's take a look at the onMessage method.…This method receives the message from the client,…and in our example we also want…to broadcast the message to all connected clients.…So if you're a member, all sessions are stored…in the list in the room instance.…And to send a message to a client,…the client session is required.…This is because within the session object…is an instance of the remote endpoint class…that represents the client as is able…to send messages to the client.…
And to broadcast a message, we must retrieve…a list of all the sessions for a given room…and iterate over those sessions…and send the same message to all those clients.…Remember that we've stored the room name…in the session object, and we have…a convenience method that retrieves the room name.…So within the onMessage method, we're going…to extract the room from the session.…So we're going to do extract using our utility method…
Join Alex Theedom as he guides you through the lifecycle of a WebSocket connection, and discusses the Java EE WebSocket programming methodologies: annotation and programmatic. He shows how to secure and encrypt WebSocket endpoints and use simple techniques to test their implementation. In addition, he explains how to integrate the JSON-processing API and build a front-end and server based WebSocket client.
- WebSocket usage
- WebSocket lifecycle and topology
- WebSocket front end and back end
- WebSocket methodologies
- Annotation methodology and programmatic methodology
- Coding a client API
- Using the JSON Processing API
- Coding the encoder and decoder
- Building the front end
- Testing WebSocket endpoints
Skill Level Intermediate
Java Platforms Compared: SE vs EE vs MEwith Peggy Fisher25m 38s Intermediate
1. Introduction to WebSocket
2. WebSockets Front End and Back End
3. Project Application and Structure
4. Java EE WebSocket API
5. Messages and Encoding
6. Build Web Front End
7. WebSocket Security
8. Testing WebSocket Endpoints
Next steps1m 37s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.