简介
tekixquic 是基于 Xquic+libev 进行二次封装的Android sdk库,为了方便理解和使用,沿用了okhttp的封装方式模式,同时沿用了短链接和长链接的思维。通过get跟post接口可以快速的实现数据传输
sdk导入
第一步:引入maven 在allprojects中引入(目前是snapshot版本所有暂时需要)
maven { url “https://s01.oss.sonatype.org/content/repositories/snapshots” }
第二步:导入sdk
implementation ‘io.github.yangqingyuan:teki-quic:1.0.0.1-SNAPSHOT’
使用方式
Get 请求
val xquicClient = XquicClient.Builder()
.connectTimeOut(13)
.ccType(CCType.BBR) //拥塞算法
.build()
val xRequest = XRequest.Builder()
.url("https://192.168.10.245:8443")
.addHeader("testA", "testA")// 可选,携带自定义头信息
.get() //Default
.build()
val startTime = System.currentTimeMillis()
xquicClient.newCall(xRequest).enqueue(object : XCallBack {
override fun onFailure(call: XCall, exception: Exception) {
XLogUtils.error(exception.message)
}
override fun onResponse(call: XCall, xResponse: XResponse) {
XLogUtils.info(
" java 花费时间 ${(System.currentTimeMillis() - startTime)} ms,content=${xResponse.xResponseBody.getData()}"
)
}
})
POST 请求
val xquicClient = XquicClient.Builder()
.connectTimeOut(13)
.ccType(CCType.BBR) //拥塞算法
.build()
val xRequestBody =XRequestBody.create(XMediaType.parse(XMediaType.MEDIA_TYPE_TEXT), "test")
val xRequest = XRequest.Builder()
.url("https://192.168.10.245:8443")
.addHeader("testA", "testA")// 可选,携带自定义头信息
.post(xRequestBody)
.build()
val startTime = System.currentTimeMillis()
xquicClient.newCall(xRequest).enqueue(object : XCallBack {
override fun onFailure(call: XCall, exception: Exception) {
XLogUtils.error(exception.message)
}
override fun onResponse(call: XCall, xResponse: XResponse) {
XLogUtils.info(
" java 花费时间 ${(System.currentTimeMillis() - startTime)} ms,content=${xResponse.xResponseBody.getData()}"
)
}
})
转载请标明来源
|