Amazon API Gateway added support for WebSockets in December, 2018. The original launch announcement includes a demo app that relays messages between clients.
This Android app provides the ability to read and write messages to that WebSocket endpoint, hosted in Amazon API Gateway.
To use it:
- Deploy the Simple WebSockets Chat App.
- Copy the WSS URL that is created above. It should look something like
wss://YOUR_APP_ID.execute-api.YOUR_REGION.amazonaws.com/YOUR_STAGE
. Set it as the value ofwebsocket_url
inapp/src/main/res/values/strings.xml
. - Import this Project into Android Studio
- Build and Deploy
Try sending a message to API Gateway with wscat
:
wscat -c <your_url>
{"action": "sendmessage", "data": "Hello from the other side."}
Check what happens on the app. You should see the message there.
You can click the "send message" button in the app to send a message the listener, too.
Two version of the app are provided: