File tree Expand file tree Collapse file tree 5 files changed +31
-3
lines changed
src/main/java/moe/codeest/rxsocketclient
app/src/main/java/moe/codeest/rxsocketclientdemo Expand file tree Collapse file tree 5 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -40,25 +40,33 @@ SocketClient mClient = RxSocketClient
4040### connect
4141``` java
4242Disposable ref = mClient. connect()
43- ... // anything else what you can do with RxJava
43+ ... // anything else what you can do with RxJava
4444 .observeOn(AndroidSchedulers . mainThread())
4545 .subscribe(new SocketSubscriber () {
4646 @Override
4747 public void onConnected () {
48+ // onConnected
4849 Log . e(TAG , " onConnected" );
4950 }
5051
5152 @Override
5253 public void onDisconnected () {
54+ // onDisconnected
5355 Log . e(TAG , " onDisconnected" );
5456 }
5557
5658 @Override
5759 public void onResponse (@NotNull byte [] data ) {
58- // receive data
60+ // receive data
5961 Log . e(TAG , Arrays . toString(data));
6062 }
61- });
63+ }, new Consumer<Throwable > () {
64+ @Override
65+ public void accept (Throwable throwable ) throws Exception {
66+ // onError
67+ Log . e(TAG , throwable. toString());
68+ }
69+ });
6270```
6371
6472### disconnect
Original file line number Diff line number Diff line change 11apply plugin : ' java-library'
22apply plugin : ' kotlin'
33
4+ // JitPack Maven
5+ apply plugin : ' com.github.dcendents.android-maven'
6+ // Group
7+ group= ' com.github.codeestX'
8+
49dependencies {
510 implementation fileTree(dir : ' libs' , include : [' *.jar' ])
611 compile " org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version "
Original file line number Diff line number Diff line change @@ -99,4 +99,8 @@ class SocketClient(val mConfig: SocketConfig) {
9999 fun sendData (string : String ) {
100100 sendData(string.toByteArray(charset = mConfig.mCharset))
101101 }
102+
103+ fun isConnecting (): Boolean {
104+ return mSocket.isConnected
105+ }
102106}
Original file line number Diff line number Diff line change 1313
1414import io .reactivex .android .schedulers .AndroidSchedulers ;
1515import io .reactivex .disposables .Disposable ;
16+ import io .reactivex .functions .Consumer ;
1617import kotlin .text .Charsets ;
1718import moe .codeest .rxsocketclient .RxSocketClient ;
1819import moe .codeest .rxsocketclient .SocketClient ;
@@ -81,21 +82,30 @@ private void connect() {
8182 .subscribe (new SocketSubscriber () {
8283 @ Override
8384 public void onConnected () {
85+ //onConnected
8486 Log .e (TAG , "onConnected" );
8587 }
8688
8789 @ Override
8890 public void onDisconnected () {
91+ //onDisconnected
8992 Log .e (TAG , "onDisconnected" );
9093 //re-connect
9194// connect();
9295 }
9396
9497 @ Override
9598 public void onResponse (@ NotNull byte [] data ) {
99+ //receive data
96100 Log .e (TAG , Arrays .toString (data ));
97101 tvReceive .setText (Arrays .toString (data ));
98102 }
103+ }, new Consumer <Throwable >() {
104+ @ Override
105+ public void accept (Throwable throwable ) throws Exception {
106+ //onError
107+ Log .e (TAG , throwable .toString ());
108+ }
99109 });
100110 }
101111
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ buildscript {
99 dependencies {
1010 classpath ' com.android.tools.build:gradle:3.0.0-alpha4'
1111 classpath " org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version "
12+ classpath ' com.github.dcendents:android-maven-gradle-plugin:1.5'
1213
1314 // NOTE: Do not place your application dependencies here; they belong
1415 // in the individual module build.gradle files
You can’t perform that action at this time.
0 commit comments