https://github.com/chen0040/spring-websocket-android-client-demo
Demo on how to integrate spring websocket on the server with android client
https://github.com/chen0040/spring-websocket-android-client-demo
android spring-boot websocket
Last synced: 11 months ago
JSON representation
Demo on how to integrate spring websocket on the server with android client
- Host: GitHub
- URL: https://github.com/chen0040/spring-websocket-android-client-demo
- Owner: chen0040
- License: mit
- Created: 2017-12-08T17:59:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-10T05:57:09.000Z (over 8 years ago)
- Last Synced: 2025-06-12T07:09:41.096Z (about 1 year ago)
- Topics: android, spring-boot, websocket
- Language: Java
- Size: 937 KB
- Stars: 23
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spring-websocket-android-client-demo
Demo of connecting android client to spring web application via websocket
# Usage
### WebSocket Spring Boot Server
git clone this project, run the "./make.ps1" powershell script in the project root directory to build spring-boot-application.jar
into the "bin" folder.
Run the following command to start the spring-boot-application at http://localhost:8080
```bash
java -jar bin/spring-boot-application.jar
```
The spring-boot-application defines an end point at http://localhost:8080/my-ws and sends a ping message to any connected client that subscribe to its topic "/topics/event" every 10 seconds. the angularjs demo can be viewed by navigating to http://localhost:8080 on your web browser.
### Android WebSocket Client
The spring-boot-android-client project contains the implementation of the android websocket client. To subscribe to the "/topics/event" at http://localhost:8080/my-ws, run the following android codes:
```java
SpringBootWebSocketClient client = new SpringBootWebSocketClient();
client.setId("sub-001");
TopicHandler handler = client.subscribe("/topics/event");
handler.addListener(new StompMessageListener() {
@Override
public void onMessage(StompMessage message) {
System.out.println(message.getHeader("destination") + ": " + message.getContent());
}
});
client.connect("ws://localhost:8080/my-ws/websocket");
Thread.sleep(60000L);
client.disconnect();
```