Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

AndroidAsync

> 编程语言
Open source

Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.

7.5K stars0 likes2 views
WebsiteGitHub

About

Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.

AndroidAsync

AndroidAsync is a low level network protocol library. If you are looking for an easy to use, higher level, Android aware, http request library, check out Ion (it is built on top of AndroidAsync). The typical Android app developer would probably be more interested in Ion.

But if you're looking for a raw Socket, HTTP(s) client/server, and WebSocket library for Android, AndroidAsync is it.

Features

  • Based on NIO. Single threaded and callback driven.
  • All operations return a Future that can be cancelled
  • Socket client + socket server
  • HTTP client + server
  • WebSocket client + server

Download

Download the latest JAR or grab via Maven:

xml
<dependency>
    <groupId>com.koushikdutta.async</groupId>
    <artifactId>androidasync</artifactId>
    <version>(insert latest version)</version>
</dependency>

Gradle:

groovy
dependencies {
    compile 'com.koushikdutta.async:androidasync:2.+'
}

Download a url to a String

java
// url is the URL to download.
AsyncHttpClient.getDefaultInstance().getString(url, new AsyncHttpClient.StringCallback() {
    // Callback is invoked with any exceptions/errors, and the result, if available.
    @Override
    public void onCompleted(Exception e, AsyncHttpResponse response, String result) {
        if (e != null) {
            e.printStackTrace();
            return;
        }
        System.out.println("I got a string: " + result);
    }
});

Download JSON from a url

java
// url is the URL to download.
AsyncHttpClient.getDefaultInstance().getJSONObject(url, new AsyncHttpClient.JSONObjectCallback() {
    // Callback is invoked with any exceptions/errors, and the result, if available.
    @Override
    public void onCompleted(Exception e, AsyncHttpResponse response, JSONObject result) {
        if (e != null) {
            e.printStackTrace();
            return;
        }
        System.out.println("I got a JSONObject: " + result);
    }
});

Or for JSONArrays...

java
// url is the URL to download.
AsyncHttpClient.getDefaultInstance().getJSONArray(url, new AsyncHttpClient.JSONArrayCallback() {
    // Callback is invoked with any exceptions/errors, and the result, if available.
    @Override
    public void onCompleted(Exception e, AsyncHttpResponse response, JSONArray result) {
        if (e != null) {
            e.printStackTrace();
            return;
        }
        System.out.println("I got a JSONArray: " + result);
    }
});

Download a url to a file

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

Caching is supported too

java
// arguments are the http client, the directory to store cache files,
// and the size of the cache in bytes
ResponseCacheMiddleware.addCache(AsyncHttpClient.getDefaultInstance(),
                                  getFileStreamPath("asynccache"),
                                  1024 * 1024 * 10);

Need to do multipart/form-data uploads? That works too.

…

Can also create web sockets:

…

AndroidAsync also let's you create simple HTTP servers:

java
AsyncHttpServer server = new AsyncHttpServer();

List<WebSocket> _sockets = new ArrayList<WebSocket>();

server.get("/", new HttpServerRequestCallback() {
    @Override
    public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
        response.send("Hello!!!");
    }
});

// listen on port 5000
server.listen(5000);
// browsing http://localhost:5000 will return Hello!!!

And WebSocket Servers:

…

Futures

All the API calls return Futures.

java
Future<String> string = client.getString("http://foo.com/hello.txt");
// this will block, and may also throw if there was an error!
String value = string.get();

Futures can also have callbacks...

java
Future<String> string = client.getString("http://foo.com/hello.txt");
string.setCallback(new FutureCallback<String>() {
    @Override
    public void onCompleted(Exception e, String result) {
        System.out.println(result);
    }
});

For brevity...

java
client.getString("http://foo.com/hello.txt")
.setCallback(new FutureCallback<String>() {
    @Override
    public void onCompleted(Exception e, String result) {
        System.out.println(result);
    }
});

Issues· 355 open

View all issuesOpen on GitHub
  • #725

    Request: a private channel for reporting a security issue (no details here)

    Updated Aug 28, 2026
  • #724

    DocumentParser: XML body parsed without XXE hardening (CWE-611)

    Updated Jun 24, 2026
  • #723

    IndexOutOfBoundsException

    Updated Jul 3, 2025
  • #722

    Bad Record MAC alert from Client after Server sent Finished Message in TLS1.3

    Updated Mar 6, 2025
  • #711

    exception when connect to server

    Updated Aug 15, 2024
  • #719

    How to do server support Multi-Threading and High concurrency

    Updated May 27, 2024
  • #720

    NullPointerException in HybiParser ( version 3.1.0 )

    Updated Apr 15, 2024
  • #717

    Does the library use some Tracking link?

    Updated Sep 26, 2023
  • #351

    stop() Doesn't Stop the AsyncHttpServer

    Updated Aug 28, 2023
  • #708

    mDataHandler failed to consume data

    Updated Aug 8, 2023

> Tags

Java

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 2, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言