View on GitHub

AndroidAsync

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

Download this project as a .zip fileDownload this project as a tar.gz file

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 client/server, WebSocket, and Socket.IO library for Android, AndroidAsync is it.

Features

Download

Download [the latest JAR](https://search.maven.org/remote_content?g=com.koushikdutta.async&a=androidasync&v=LATEST ) or grab via Maven:

Gradle:

Download a url to a String

Download JSON from a url

Or for JSONArrays...

Download a url to a file

Caching is supported too

Can also create web sockets:

AndroidAsync also supports socket.io (version 0.9.x)

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

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:

```java server.websocket("/live", new WebSocketRequestCallback() { @Override public void onConnected(final WebSocket webSocket, AsyncHttpServerRequest request) { _sockets.add(webSocket);

    //Use this to clean up any references to your websocket

webSocket.setClosedCallback(new CompletedCallback() { @Override public void onCompleted(Exception ex) { try { if (ex != null) Log.e("WebSocket", "Error"); } finally { _sockets.remove(webSocket); } } });

    webSocket.setStringCallback(new StringCallback() {

@Override public void onStringAvailable(String s) { if ("Hello Server".equals(s)) webSocket.send("Welcome Client!"); } });

}

});

//..Sometime later, broadcast! for (WebSocket socket : _sockets) socket.send("Fireball!"); ```

Futures

All the API calls return Futures.

Futures can also have callbacks...

For brevity...

Note on SSLv3

https://github.com/koush/AndroidAsync/issues/174