Skip to content

ocastroa/java-websocket-demo

Repository files navigation

Java WebSocket Programming | Android and Spring Boot

A simple demo on how to set up an Android Client that connects to a WebSocket server using Spring Boot. For the client-to-client demo, we use PubNub's Android SDK to securely and reliably send data between clients without setting up a server.

Setup

  1. Sign up for a free PubNub account to get your Pub/Sub API keys.
PubNub Signup
  1. Clone the repo.
git clone https://github.com/ocastroa/java-websocket-demo
  1. To run the client-to-server demo, open the directory JavaWebSocketClient in Android Studio and javawebsocketserver in your favorite text editor, like VS Code

  2. To start the server, go to the root directory of javawebsocketserver in your terminal and type the following command:

gradle bootRun
  1. Run the client on the Android emulator. Once the app opens, click any of the four buttons and see the response from the server in the text below the buttons.

Screenshot of client-to-server demo

  1. To run the client-to-client demo, open the directory PubNubJavaClient in Android Studio. Go to MainActivity.java and replace 'ENTER_YOUR_PUB_KEY' and 'ENTER_YOUR_SUB_KEY' with the keys you got from Step 1.

  2. Run the cient on two different emulators. Click any of the buttons and watch as mesages are published to both emulators.

Screenshot of client-to-server demo

Build Your Own WebSocket Demo with Android and Spring Boot

To learn more about this project or if you want to build this project from scratch, check out the tutorial.

PubNub Blog

About

Java WebSocket Demo with Android and Spring Boot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages