Android Kotlin Web Server

Sample code below is a very simple web server written in Kotlin. A [Start] button to start listening, a [Stop] button to stop listening and text view to display WiFi address.

Remember to add these 2 permissions else the app will crash upon start.

Codes for the 2 class variable and in my example I had the port hard coded to 8888.

Codes for getting WiFi address can be found at “Android Kotlin Get WiFi IP” post. And the codes for the button listener below.

After that you will also be needing a client handler class. Codes below the screenshot. Content length HTTP header is very important else it will not know when to stop.

Successful test with the apps listed below.
1. curl in Mac terminal
2. Chrome in Mac

< Back to all the stories I had written

A software engineer, a rock climbing, diving & inline skating enthusiast, a husband, a father.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store