minimal-ktor-server-android
minimal-ktor-server-android copied to clipboard
Example Netty-based Ktor server for Android 5+
Example Netty-based Ktor server for Android 5+
This repo implements an Android 5+ app that runs a Netty-powered KTor server when the app is in the foreground.
The server runs on 0.0.0.0:13276 without TLS.
MainActivity contains the KTor server code.
Endpoints
This app implements two endpoints:
GET /
It returns a 200 OK with a text body (text/plain) that contains the model name of the device the server runs on.
WebSocket /ws
This is a WebSocket endpoint that implements the following protocol:
- Client connects to server.
- Server sends text message to client.
- Server waits for client to send message back (any message).
- Server closes connection as soon as message from client is received.
Automated test
ServerTest contains a test that checks the endpoints above.
Make sure to set the right IP to your Android device on your WiFi network.
Licence
This repo is in the public domain.