Simple and Small footprint TCP/IP Web Server for Android in Java
This is standalone, multithreaded, almost or No dependancy ! http server in Java with example use in Android.
Features supported
- Support basic GET, POST requests
- Render html files
- Render jpeg,png,gif
- Custom api for dynamic web pages (mvc)
- Support javascript rendring
- Multithreaded, support mulitple client
What it does not do?
- File upload, video rendering
-
Add the follow permission to your manifest file
<uses-permission android:name="android.permission.INTERNET"/>
-
Copy TinyWebServer.java class from src dir to your android project package
-
Call following from android service or process
@Override protected void onCreate(Bundle savd){ super.onCreate(savd); ... //call contructor with local ip, port , public html directory path TinyWebServer.startServer("localhost",9000, "/web/public_html"); } @Override public void onDestroy(){ super.onDestroy(); //stop webserver on destroy of service or process TinyWebServer.stopServer(); }
-
Copy AppApis.java from src directory
-
keep the package name same for AppApis.java like "appapis.queryfiles"
-
open AppApis.java and write your own mehtod/function inside AppApis.java for example,
public String myfirstapi(HashMap qparms){ //todo - write your api logic here //qparms is collection of GET and POST parameters }
you can access this api -> http://localhost:9000/myfirstapi
- Run the code and hit browser with http://localhost:9000/helloworld
- here port number is 9000
- localhost or your device ip address
- helloworld is api method inside AppApis.java
Design, Build, Tested by
twitter , github /@sonuauti