• Stars
    star
    434
  • Rank 96,529 (Top 2 %)
  • Language
    Java
  • Created almost 11 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android Web Server (NanoHttpd)

AndroidWebServer

Android Arsenal Platform API Twitter

This is a sample project for creating an Android Web Server using the NanoHTTPD library.

Usage

  1. To make an Android Web Server add NanoHTTPD dependency in your build.gradle file:

    compile 'org.nanohttpd:nanohttpd:2.2.0'
  2. After that, you must create an Android Web Server Class this way:

    public class AndroidWebServer extends NanoHTTPD {
    
        public AndroidWebServer(int port) {
            super(port);
        }
    
        public AndroidWebServer(String hostname, int port) {
            super(hostname, port);
        }
        
        //...
    }
  3. Add serve() method in your Android Web Server Class :

    @Override
    public Response serve(IHTTPSession session) {
        String msg = "<html><body><h1>Hello server</h1>\n";
        Map<String, String> parms = session.getParms();
        if (parms.get("username") == null) {
            msg += "<form action='?' method='get'>\n";
            msg += "<p>Your name: <input type='text' name='username'></p>\n";
            msg += "</form>\n";
        } else {
            msg += "<p>Hello, " + parms.get("username") + "!</p>";
    	}
        return newFixedLengthResponse( msg + "</body></html>\n" );
    }

    serve() is a very important method beacause this is the response sent by your web server.

  4. You can now instantiate and start your server in your activity. (Full implementation here)

    AndroidWebServer androidWebServer = new AndroidWebServer(port);
    androidWebServer.start();
    androidWebServer.stop();

LICENCE

AndroidWebServer by Lopez Mikhael is licensed under a Apache License 2.0.

More Repositories

1

CircularImageView

Create circular ImageView in Android in the simplest way possible
Kotlin
1,944
star
2

CircularProgressBar

Create circular ProgressBar in Android ⭕
Kotlin
1,683
star
3

CircularFillableLoaders

Realize a beautiful circular fillable loaders to be used for splashscreen 🌊
Java
1,220
star
4

BestAndroidGists

Find best Android Gist 🔥
884
star
5

RxAnimation

Simple way to animate your views on Android with Rx 🚀
Kotlin
594
star
6

CleanRxArchitecture

Clean Rx Kotlin Architecture sample on GitHub Api 🚀
Kotlin
386
star
7

LazyDatePicker

LazyDatePicker an alternative to the native Android Date Picker 📅
Java
372
star
8

RateBottomSheet

To help to promote your android app by prompting users to rate your app in a BottomSheet ⭐️
Kotlin
307
star
9

GradientView

Create gradient view in Android in the simplest way possible 🌈
Kotlin
198
star
10

HFRecyclerView

Add Header and/or Footer in your RecyclerView in the simplest way possible.
Kotlin
171
star
11

CircleView

Create circular view in android (change color, border & shadow) ⚫
Kotlin
166
star
12

Biometric

The easiest way is to use the new version of Biometric under AndroidX 🔒
Kotlin
141
star
13

PokeCardCompose

PokeCard Compose is a demo app 100% write in Compose, Flow and Koin based on MVI Clean Architecture 🐱⚡️
Kotlin
114
star
14

SaveInsta

Example dynamic update of your theme based on a main color
Java
85
star
15

AutoScrollTextView

Sample Android application show how to set auto scroll in text view in android.
Java
51
star
16

FavoriteAndroidLibrary

My Farorite Android Library
49
star
17

MyToast

Custom Toast on Android
Java
39
star
18

DualShot

With DualShot you take two photos with the front and the back camera, and share both of them in a single image.
Java
23
star
19

WebSideMVC

Structure MVC for Web Side in PHP
PHP
1
star