Commit 7a4f80b4 by 杜祥龙

fix 记录消息格式

Signed-off-by: sdvdxl杜龙少 <sdvdxl@163.com>
parent e86f1cc0
......@@ -45,7 +45,6 @@ public class GatewayDevice {
message.put("params", params);
tcpClient.send(JSON.toJSONString(message) + "\n");
String respMsg = tcpClient.receive(MAX_WAIT_TIME_MILLS);
System.out.println(respMsg);
JSONObject respMap = JSON.parseObject(respMsg);
boolean success = respMap.getIntValue("code") == 200;
if (!success) {
......@@ -72,7 +71,6 @@ public class GatewayDevice {
message.put("params", params);
tcpClient.send(JSON.toJSONString(message) + "\n");
String respMsg = tcpClient.receive(MAX_WAIT_TIME_MILLS);
System.out.println(respMsg);
JSONObject resp = JSON.parseObject(respMsg);
if (resp.getIntValue("code") != 200) {
System.out.println("gateway login failed,resp:" + respMsg);
......@@ -120,7 +118,8 @@ public class GatewayDevice {
new MessageListener() {
@Override
public void onMessage(String message) {
System.out.println(message);
// TODO 指令处理
System.out.print("ON_MESSAGE_TODO:" + message);
}
}));
}
......
......@@ -61,7 +61,10 @@ public class TcpClient {
throw new RuntimeException("output channel closed");
}
System.out.println("SEND => " + message);
System.out.print("SEND ==> " + message);
if (!message.endsWith("\n")){
System.out.println();
}
outToServer.writeBytes(message);
return this;
}
......@@ -96,7 +99,9 @@ public class TcpClient {
* @throws IOException
*/
public String receive() throws IOException {
return inFromServer.readLine();
String msg = inFromServer.readLine();
System.out.println("RECE <== " + msg + "\n");
return msg;
}
/**
......@@ -107,7 +112,7 @@ public class TcpClient {
*/
public String receive(int timeoutMill)
throws InterruptedException, ExecutionException, TimeoutException {
FutureTask<String> futureTask = new FutureTask<>(() -> inFromServer.readLine());
FutureTask<String> futureTask = new FutureTask<>(this::receive);
futureTask.run();
return futureTask.get(timeoutMill, TimeUnit.MILLISECONDS);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment