|
|
@ -24,6 +24,7 @@ public class TCPTask { |
|
|
|
public TcpServer server ; |
|
|
|
Thread myThread; |
|
|
|
Boolean stopThread = false; |
|
|
|
Integer messageCount = 0; |
|
|
|
// TCP task |
|
|
|
|
|
|
|
public void sendTcpCallBack(String send_msg){ |
|
|
@ -32,7 +33,6 @@ public class TCPTask { |
|
|
|
} |
|
|
|
|
|
|
|
public void task(final Integer port, final UniJSCallback uniJSCallback){ |
|
|
|
// Android 4.0 之后不能在主线程中请求HTTP请求 |
|
|
|
// System.out.println("AsyncTask thread running... ==>>>44444444:"+port+ server.isServerBound()); |
|
|
|
this.server = new TcpServer(); |
|
|
|
// this.server = server.initSocket(port,uniJSCallback); |
|
|
@ -59,24 +59,30 @@ public class TCPTask { |
|
|
|
// String send_msg = "5501a23070b6"; //回发socket消息,确认接收 |
|
|
|
// send_msg = SocketHelper.getMessageByReadLine(send_msg); |
|
|
|
// server.sendMessage(send_msg, SocketConfig.UTF_8);//回发消息 |
|
|
|
|
|
|
|
messageCount++; |
|
|
|
JSONObject data = new JSONObject(); |
|
|
|
data.put("code", "1"); |
|
|
|
data.put("count", messageCount); |
|
|
|
data.put("threadID", Thread.currentThread().getId()); |
|
|
|
data.put("threadName", Thread.currentThread().getName()); |
|
|
|
// data.put("message", server.); |
|
|
|
// data.put("message", tcp_receive_message); |
|
|
|
data.put("message", tcp_receive_message); |
|
|
|
// myCallback.tcpCallback(data); |
|
|
|
// myTcpCallback.tcpCallback(data);//回调到zmtClass给uni端 |
|
|
|
|
|
|
|
uniJSCallback.invokeAndKeepAlive(data); |
|
|
|
try { |
|
|
|
Thread.sleep(100); //定义休眠时间 |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
try { |
|
|
|
Thread.sleep(1000); //定义休眠时间 |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
Thread.sleep(1000); //定义休眠时间 |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|