android async socket.io,底层网络协议库 – AndroidAsync

AndroidAsync

AndroidAsync是一个底层网络协议库。如果你正在寻求一个便于使用,高级的,适配Android的,http请求的库,可以查看Ion。

特性

基于NIO。一个县城,通过回调驱动。高效率。?

所有的操作返回一个可以取消的Future。

Socket客户端+套接字服务

HTTP客户端+服务

WebSocket客户端+服务

Socket.IO 客户端

Download

Maven:

com.koushikdutta.async

androidasync

(insert latest version)

Gradle:

dependencies {

compile 'com.koushikdutta.async:androidasync:2.+'

}

将url下载为一个字符串

// 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);

}

});

从url下载JSON

// 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);

}

});

JSON Arrays

// 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);

}

});

将url下载为文件

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());

}

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值