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
40
40
### connect
41
41
``` java
42
42
Disposable ref = mClient. connect()
43
- ... // anything else what you can do with RxJava
43
+ ... // anything else what you can do with RxJava
44
44
.observeOn(AndroidSchedulers . mainThread())
45
45
.subscribe(new SocketSubscriber () {
46
46
@Override
47
47
public void onConnected () {
48
+ // onConnected
48
49
Log . e(TAG , " onConnected" );
49
50
}
50
51
51
52
@Override
52
53
public void onDisconnected () {
54
+ // onDisconnected
53
55
Log . e(TAG , " onDisconnected" );
54
56
}
55
57
56
58
@Override
57
59
public void onResponse (@NotNull byte [] data ) {
58
- // receive data
60
+ // receive data
59
61
Log . e(TAG , Arrays . toString(data));
60
62
}
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
+ });
62
70
```
63
71
64
72
### disconnect
Original file line number Diff line number Diff line change 1
1
apply plugin : ' java-library'
2
2
apply plugin : ' kotlin'
3
3
4
+ // JitPack Maven
5
+ apply plugin : ' com.github.dcendents.android-maven'
6
+ // Group
7
+ group= ' com.github.codeestX'
8
+
4
9
dependencies {
5
10
implementation fileTree(dir : ' libs' , include : [' *.jar' ])
6
11
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) {
99
99
fun sendData (string : String ) {
100
100
sendData(string.toByteArray(charset = mConfig.mCharset))
101
101
}
102
+
103
+ fun isConnecting (): Boolean {
104
+ return mSocket.isConnected
105
+ }
102
106
}
Original file line number Diff line number Diff line change 13
13
14
14
import io .reactivex .android .schedulers .AndroidSchedulers ;
15
15
import io .reactivex .disposables .Disposable ;
16
+ import io .reactivex .functions .Consumer ;
16
17
import kotlin .text .Charsets ;
17
18
import moe .codeest .rxsocketclient .RxSocketClient ;
18
19
import moe .codeest .rxsocketclient .SocketClient ;
@@ -81,21 +82,30 @@ private void connect() {
81
82
.subscribe (new SocketSubscriber () {
82
83
@ Override
83
84
public void onConnected () {
85
+ //onConnected
84
86
Log .e (TAG , "onConnected" );
85
87
}
86
88
87
89
@ Override
88
90
public void onDisconnected () {
91
+ //onDisconnected
89
92
Log .e (TAG , "onDisconnected" );
90
93
//re-connect
91
94
// connect();
92
95
}
93
96
94
97
@ Override
95
98
public void onResponse (@ NotNull byte [] data ) {
99
+ //receive data
96
100
Log .e (TAG , Arrays .toString (data ));
97
101
tvReceive .setText (Arrays .toString (data ));
98
102
}
103
+ }, new Consumer <Throwable >() {
104
+ @ Override
105
+ public void accept (Throwable throwable ) throws Exception {
106
+ //onError
107
+ Log .e (TAG , throwable .toString ());
108
+ }
99
109
});
100
110
}
101
111
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ buildscript {
9
9
dependencies {
10
10
classpath ' com.android.tools.build:gradle:3.0.0-alpha4'
11
11
classpath " org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version "
12
+ classpath ' com.github.dcendents:android-maven-gradle-plugin:1.5'
12
13
13
14
// NOTE: Do not place your application dependencies here; they belong
14
15
// in the individual module build.gradle files
You can’t perform that action at this time.
0 commit comments