{"id":23338290,"url":"https://github.com/abhirockzz/websocket-chat","last_synced_at":"2025-04-09T22:32:18.232Z","repository":{"id":79125482,"uuid":"83510377","full_name":"abhirockzz/websocket-chat","owner":"abhirockzz","description":"Sample code for the 'Java WebSocket API Handbook'","archived":false,"fork":false,"pushed_at":"2017-03-01T04:15:00.000Z","size":17,"stargazers_count":9,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T00:24:47.003Z","etag":null,"topics":["jsr356","tyrus","websocket"],"latest_commit_sha":null,"homepage":"https://www.gitbook.com/book/abhirockzz/java-api-for-websocket-handbook/details","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhirockzz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-01T04:10:07.000Z","updated_at":"2022-07-06T08:35:28.000Z","dependencies_parsed_at":"2023-03-13T20:10:54.451Z","dependency_job_id":null,"html_url":"https://github.com/abhirockzz/websocket-chat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhirockzz%2Fwebsocket-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhirockzz%2Fwebsocket-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhirockzz%2Fwebsocket-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhirockzz%2Fwebsocket-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhirockzz","download_url":"https://codeload.github.com/abhirockzz/websocket-chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248123492,"owners_count":21051480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jsr356","tyrus","websocket"],"created_at":"2024-12-21T03:13:30.953Z","updated_at":"2025-04-09T22:32:18.222Z","avatar_url":"https://github.com/abhirockzz.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"The is a chat application (a canonical use case for WebSocket) built using the [Java WebSocket API (JSR 356)](jcp.org/en/jsr/detail?id=356). This is meant to help understand the API usage and try it hands on (this is not a full-blown chat service)\r\n\r\n## Components\r\n\r\n- Uses the [Tyrus](https://tyrus.java.net) implementation for the core logic\r\n- Leverages the [Grizzly](https://grizzly.java.net/) container support available in Tyrus\r\n- Packaged as a standalone JAR \r\n\r\n## Build \u0026 run\r\n\r\nThe application is a Maven project\r\n\r\n- To build, just execute `mvn clean install` which will produce an independent (fat/uber) JAR\r\n- Run it using `java -jar target/websocket-chat.jar`\r\n\r\n## Features\r\n\r\nHere is what you can do with the chat application\r\n\r\n- Join the chat room\r\n- Send public messages\r\n- Send private messages\r\n- Get notified about new users joining\r\n- Leave the chat room\r\n- Get notified another user leaves the chat room\r\n\r\n## Code\r\n\r\nBefore you explore the source code yourself, here is quick overview\r\n\r\n|Class(es)|Category|Description|\r\n|---------|--------|-----------|\t\t\r\n|`ChatServer`|Core|It contains the core business logic of the application|\r\n|`WebSocketServerManager`|Bootstrap|Manages bootstrap and shutdown process of the WebSocket container|\r\n|`ChatMessage`,\u003cbr\u003e`DuplicateUserNotification`,\u003cbr\u003e`LogOutNotification`,\u003cbr\u003e`NewJoineeNotification`,\u003cbr\u003e`Reply`,\u003cbr\u003e`WelcomeMessage`|Domain objects|Simple POJOs to model the application level entities|\r\n|`ChatMessageDecoder`|Decoder|Converts chats sent by users into Java (domain) object which can be used within the application|\r\n|`DuplicateUserMessageEncoder`\u003cbr\u003e,`LogOutMessageEncoder`,\u003cbr\u003e`NewJoineeMessageEncoder`,\u003cbr\u003e`ReplyEncoder`,\u003cbr\u003e`WelcomeMessageEncoder`|Encoder(s)|Converts Java (domain) objects into native (text) payloads which can be sent over the wire using the WebSocket protocol|\r\n\r\n\r\n\u003e **Unit tests**: The unit tests use the Java client API implementation in Tyrus\r\n\r\n## Try it out\r\n\r\nYou would need a WebSocket client for this example - try the [Simple WebSocket Client](https://chrome.google.com/webstore/detail/simple-websocket-client/pfdhoblngboilpfeibdedpjgfnlcodoo?hl=en) which is a Chrome browser plugin. Here is a transcript\r\n\r\n- Users **foo** and **bar** join the chatroom. To do so, you need to connect to the WebSocket endpoint URL e.g. `ws://localhost:8080/chat/foo/` (do the same for user **bar**). **foo** gets notified about **bar**\r\n- User **john** joins (`ws://localhost:8080/chat/john/`). **foo** and **bar** are notified\r\n- **foo** sends a message to everyone (public). Both **bar** and **john** get the message\r\n- **bar** sends a private message to **foo**. Only **foo** gets it\r\n- In the meanwhile, **john** gets bored and decides to leave the chat room. Both **foo** and **bar** get notified\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhirockzz%2Fwebsocket-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhirockzz%2Fwebsocket-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhirockzz%2Fwebsocket-chat/lists"}