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.
- Sign up for a free PubNub account to get your Pub/Sub API keys.
- Clone the repo.
git clone https://github.com/ocastroa/java-websocket-demo
-
To run the client-to-server demo, open the directory JavaWebSocketClient in Android Studio and javawebsocketserver in your favorite text editor, like VS Code
-
To start the server, go to the root directory of javawebsocketserver in your terminal and type the following command:
gradle bootRun
- 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.
-
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.
-
Run the cient on two different emulators. Click any of the buttons and watch as mesages are published to both emulators.
To learn more about this project or if you want to build this project from scratch, check out the tutorial.