Commit 30fc1001 authored by AfirSraftGarrier's avatar AfirSraftGarrier

格式并加些打印

parent 6d69be24
...@@ -40,6 +40,7 @@ public class DeviceControllerTest { ...@@ -40,6 +40,7 @@ public class DeviceControllerTest {
String serverIp = "112.74.57.111"; String serverIp = "112.74.57.111";
int serverPort = 18889; int serverPort = 18889;
Socket socket = new Socket(serverIp, serverPort); Socket socket = new Socket(serverIp, serverPort);
socket.setKeepAlive(true);
System.out.println("connect success..."); System.out.println("connect success...");
// 事先组装好要发送的鉴权信息 // 事先组装好要发送的鉴权信息
...@@ -53,14 +54,12 @@ public class DeviceControllerTest { ...@@ -53,14 +54,12 @@ public class DeviceControllerTest {
InputStream inputStream = socket.getInputStream(); InputStream inputStream = socket.getInputStream();
// 鉴权 // 鉴权
sendAndReceive(socket, outputStream, inputStream, "auth", authSendBytes); sendAndReceive(socket, outputStream, inputStream, "auth", authSendBytes, true);
Thread.sleep(5000);
// 鉴权后做动作 // 鉴权后做动作
String request = "55AA340090000156F43D4D806827D1BB8F78C00D2B5488479CEB172C5D477C4D3023CE7B111621D4AD2C11ACAC4D876A3AC66A82F5F19000EF"; String request = "55AA340090000156F43D4D806827D1BB8F78C00D2B5488479CEB172C5D477C4D3023CE7B111621D4AD2C11ACAC4D876A3AC66A82F5F19000EF";
byte[] actionSendBytes = hex2Byte(request); byte[] actionSendBytes = hex2Byte(request);
byte[] actionResultBytes = sendAndReceive(socket, outputStream, inputStream, "action", actionSendBytes); byte[] actionResultBytes = sendAndReceive(socket, outputStream, inputStream, "action", actionSendBytes, false);
String result = "55AA1500A40035414E7DB5B3EDE72BC6BA44203F52EA0000005B"; String result = "55AA1500A40035414E7DB5B3EDE72BC6BA44203F52EA0000005B";
Assert.assertEquals(bytes2Hex(actionResultBytes), result); Assert.assertEquals(bytes2Hex(actionResultBytes), result);
...@@ -70,9 +69,13 @@ public class DeviceControllerTest { ...@@ -70,9 +69,13 @@ public class DeviceControllerTest {
} }
@SneakyThrows @SneakyThrows
private byte[] sendAndReceive(Socket socket, OutputStream outputStream, InputStream inputStream, String tag, byte[] requestBytes) { private byte[] sendAndReceive(Socket socket, OutputStream outputStream, InputStream inputStream, String tag, byte[] requestBytes, boolean isAuth) {
System.out.println(tag + " send:" + bytes2Hex(requestBytes)); System.out.println(tag + " send:" + bytes2Hex(requestBytes));
outputStream.write(requestBytes); outputStream.write(requestBytes);
outputStream.flush();
if (!isAuth) {
Thread.sleep(2000);
}
byte[] bytes = new byte[1024]; byte[] bytes = new byte[1024];
int count = inputStream.read(bytes); int count = inputStream.read(bytes);
byte[] resultBytes = new byte[count]; byte[] resultBytes = new byte[count];
......
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