Skip to content

Repository files navigation

RxSocketClient

PRs WelcomeAPILicense

RxSocketClient, Reactive Socket APIs for Android, Java and Kotlin, powered by RxJava2
RxSocketClient,支持Android,Java和Kotlin的响应式Socket APIs封装,基于RxJava2

RxJava2 Version: 2.1.1

Usage

Step 1. Add the JitPack repository to your build file

allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}

Step 2. Add the dependency

dependencies {
compile 'com.github.codeestX:RxSocketClient:v1.0.1'
}

init

SocketClientmClient = RxSocketClient
.create(newSocketConfig.Builder()
.setIp(IP)
.setPort(PORT)
.setCharset(Charsets.UTF_8)
.setThreadStrategy(ThreadStrategy.ASYNC)
.setTimeout(30 * 1000)
.build())
.option(newSocketOption.Builder()
.setHeartBeat(HEART_BEAT, 60 * 1000)
.setHead(HEAD)
.setTail(TAIL)
.build());
valuedefaultdescription
Iprequiredhost address
Portrequiredport number
CharsetUTF_8the charset when encode a String to byte[]
ThreadStrategyAsyncsending data asynchronously or synchronously
Timeout0the timeout of a connection, millisecond
HeartBeatOptionalvalue and interval of heartbeat, millisecond
HeadOptionalappending bytes at head when sending data, not included heartbeat
TailOptionalappending bytes at last when sending data, not included heartbeat

connect

Disposableref = mClient.connect()
... // anything else what you can do with RxJava
.observeOn(AndroidSchedulers.mainThread())
.subscribe(newSocketSubscriber() {
@OverridepublicvoidonConnected() {
//onConnectedLog.e(TAG, "onConnected");
}
@OverridepublicvoidonDisconnected() {
//onDisconnectedLog.e(TAG, "onDisconnected");
}
@OverridepublicvoidonResponse(@NotNullbyte[] data) {
//receive dataLog.e(TAG, Arrays.toString(data));
}
}, newConsumer<Throwable>() {
@Overridepublicvoidaccept(Throwablethrowable) throwsException {
//onErrorLog.e(TAG, throwable.toString());
}
});

disconnect

mClient.disconnect();
//orref.dispose();

sendData

mClient.sendData(bytes);
//ormClient.sendData(string);

License

 Copyright (c) 2017 codeestX
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

🚀Reactive Socket APIs for Android, Java and Kotlin, powered by RxJava2

Topics

Resources

Stars

51 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages