Skip to content

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.

Notifications You must be signed in to change notification settings

melvin7/AndroidAsync

Repository files navigation

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.get(url, newAsyncHttpClient.StringCallback(){@Override// Callback is invoked with any exceptions/errors, and the result, if available.publicvoidonCompleted(Exceptione, Stringresult){if (e != null){e.printStackTrace(); return} System.out.println("I got a string: " + result)} });

Download a url to a file

AsyncHttpClient.get(url, filename, newAsyncHttpClient.FileCallback(){@OverridepublicvoidonCompleted(Exceptione, Fileresult){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 5000AsyncHttpServermServer = newAsyncHttpServer(5000); mServer.get("/", newHttpServerRequestCallback(){@OverridepublicvoidonRequest(AsyncHttpServerRequestrequest, AsyncHttpServerResponseresponse){response.send("Hello!!!")} }); // browsing http://localhost:5000 will return Hello!!!

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published