File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed
app/src/main/java/com/pengxh/androidx/lib/view
lite/src/main/java/com/pengxh/androidx/lite/utils/socket/tcp Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public class MainActivity extends AndroidxBaseActivity<ActivityMainBinding> impl
34
34
35
35
private static final String TAG = "MainActivity" ;
36
36
private final Context context = this ;
37
- private final TcpClient tcpClient = new TcpClient ("192.168.161.200" , 3000 , this );
37
+ private final TcpClient tcpClient = new TcpClient (this );
38
38
39
39
@ Override
40
40
protected void setupTopBarLayout () {
@@ -49,7 +49,7 @@ public void onClick(View v) {
49
49
if (tcpClient .isRunning ()) {
50
50
tcpClient .stop ();
51
51
} else {
52
- tcpClient .start ();
52
+ tcpClient .start ("192.168.161.200" , 3000 );
53
53
}
54
54
}
55
55
});
Original file line number Diff line number Diff line change @@ -27,16 +27,14 @@ public class TcpClient {
27
27
private static final long RECONNECT_DELAY = 5L ;
28
28
private final Bootstrap bootStrap = new Bootstrap ();
29
29
private final NioEventLoopGroup loopGroup = new NioEventLoopGroup ();
30
- private final String host ;
31
- private final int port ;
32
30
private final OnTcpConnectStateListener listener ;
31
+ private String host ;
32
+ private int port ;
33
33
private Channel channel ;
34
34
private boolean isRunning = false ;
35
35
private int retryTimes = 0 ;
36
36
37
- public TcpClient (String host , int port , OnTcpConnectStateListener listener ) {
38
- this .host = host ;
39
- this .port = port ;
37
+ public TcpClient (OnTcpConnectStateListener listener ) {
40
38
this .listener = listener ;
41
39
bootStrap .group (loopGroup )
42
40
.channel (NioSocketChannel .class )
@@ -54,7 +52,9 @@ public boolean isRunning() {
54
52
return isRunning ;
55
53
}
56
54
57
- public void start () {
55
+ public void start (String host , int port ) {
56
+ this .host = host ;
57
+ this .port = port ;
58
58
if (isRunning ) {
59
59
return ;
60
60
}
You can’t perform that action at this time.
0 commit comments