• Stars
    star
    433
  • Rank 100,464 (Top 2 %)
  • Language
    Java
  • Created over 11 years ago
  • Updated almost 5 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,949
star
2

CircularProgressBar

Create circular ProgressBar in Android β­•
Kotlin
1,698
star
3

CircularFillableLoaders

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

BestAndroidGists

Find best Android Gist πŸ”₯
890
star
5

RxAnimation

Simple way to animate your views on Android with Rx πŸš€
Kotlin
590
star
6

CleanRxArchitecture

Clean Rx Kotlin Architecture sample on GitHub Api πŸš€
Kotlin
387
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
308
star
9

GradientView

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

HFRecyclerView

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

CircleView

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

Biometric

The easiest way is to use the new version of Biometric under AndroidX πŸ”’
Kotlin
140
star
13

PokeCardCompose

PokeCard Compose is a demo app 100% write in Compose, Flow and Koin based on MVI Clean Architecture 🐱⚑️
Kotlin
115
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