Giter Site home page Giter Site logo

dragom / androidasync Goto Github PK

View Code? Open in Web Editor NEW

This project forked from koush/androidasync

0.0 1.0 0.0 1.13 MB

Asynchronous socket and http library for android. Based on nio, not threads. Seriously though, you probably don't need this. I wrote it for a Tethering app, where hundreds of threads waiting for data input would crush your phone. Your app won't have those demands.

Java 100.00%

androidasync's Introduction

AndroidAsync

AndroidAsync is a java.nio based socket and http library for Android.

It uses java.nio to manage connections. All the connections are thus managed on a single thread, rather than one per thread. NIO is extremely efficient.

Download a url to a String

// url is the URL to download. The callback will be invoked on the UI thread
// once the download is complete.
AsyncHttpClient.download(url, new AsyncHttpClient.StringCallback() {
    @Override
    // Callback is invoked with any exceptions/errors, and the result, if available.
    public void onCompleted(Exception e, String result) {
        if (e != null) {
            e.printStackTrace();
            return;
        }
        System.out.println("I got a string: " + result);
    }
});

Download a url to a file

AsyncHttpClient.download(url, filename, new AsyncHttpClient.FileCallback() {
    @Override
    public void onCompleted(Exception e, File result) {
        if (e != null) {
            e.printStackTrace();
            return;
        }
        System.out.println("my file is available at: " + result.getAbsolutePath());
    }
});

AndroidAsync also let's you create simple HTTP servers:

// listen on port 5000
AsyncHttpServer server = new AsyncHttpServer(5000);
mServer.get("/", new HttpServerRequestCallback() {
    @Override
    public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
        response.send("Hello!!!");
    }
});
// browsing http://localhost:5000 will return Hello!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.