| | |
| | | package com.hdl.sdk.socket.client;
|
| | |
|
| | |
|
| | |
|
| | | import com.hdl.sdk.common.utils.ByteUtils;
|
| | | import com.hdl.sdk.common.utils.LogUtils;
|
| | | import com.hdl.sdk.common.utils.ThreadToolUtils;
|
| | | import com.hdl.sdk.socket.SocketBoot;
|
| | |
| | |
|
| | | /**
|
| | | * 从连接池中找出当前IP及端口的连接客户端
|
| | | *
|
| | | * @param ipAdderss 连接IP地址
|
| | | * @param port 连接端口
|
| | | * @return
|
| | | */
|
| | | public static TcpClient getTcpClientByIP(String ipAdderss,int port) {
|
| | | for(TcpClient tcpClient:tcpClientList){
|
| | | if(tcpClient.ip.equals(ipAdderss)&&tcpClient.port==port)
|
| | | {
|
| | | if (tcpClient.ip.equals(ipAdderss) && tcpClient.port == port) {
|
| | | return tcpClient;
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | tcpClientList.add(this);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | * 处理连接状态
|
| | | */
|
| | | public void onConnectStatus(int status) {
|
| | |
|
| | | ThreadToolUtils.getInstance().runOnUiThread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | |
| | | if (list != null && !list.isEmpty()) {
|
| | | for (ConnectStatusListener listener : list) {
|
| | | switch (status) {
|
| | | case ConnectStatus
|
| | | .CONNECTING:
|
| | | case 0:
|
| | | listener.onConnecting();
|
| | | break;
|
| | | case ConnectStatus
|
| | | .CONNECTED:
|
| | | case 1:
|
| | | listener.onConnected();
|
| | | break;
|
| | | case ConnectStatus
|
| | | .DISCONNECT:
|
| | | case 2:
|
| | | listener.onConnectFailed();
|
| | | break;
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | | });
|
| | |
|
| | | LogUtils.i("TcpClient onConnectStatus status:" + status);
|
| | |
|
| | | }
|
| | |
|
| | |
|