| | |
| | | if (deviceCommandMsg == null) { |
| | | continue; |
| | | } |
| | | |
| | | this.connect(); |
| | | executeCommand(deviceCommandMsg); |
| | | |
| | | Thread.sleep(200); |
| | |
| | | } |
| | | |
| | | private void listenSocketMessage() { |
| | | StringBuffer sb = new StringBuffer(); |
| | | try { |
| | | if (this.socket == null) { |
| | | return; |
| | |
| | | // 获取输入流 |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); |
| | | // 读取服务器的响应 |
| | | StringBuffer sb = new StringBuffer(); |
| | | char[] chars = new char[2048];//缓冲区 |
| | | while (true) { |
| | | reader.read(chars); |
| | | String trim = new String(chars); |
| | | sb.append(trim); |
| | | if (trim.lastIndexOf("\r\n") != -1) { |
| | | int lastIndexOf = trim.lastIndexOf("\r\n"); |
| | | if (lastIndexOf != -1) { |
| | | trim = trim.substring(0, lastIndexOf); |
| | | sb.append(trim); |
| | | break; |
| | | } |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | JSONObject header = null; |
| | | JSONObject body = null; |
| | | JSONObject response = result.getJSONObject("response"); |
| | | JSONObject header = response.getJSONObject("header"); |
| | | JSONObject body = response.getJSONObject("body"); |
| | | if (response == null) { |
| | | JSONObject request = result.getJSONObject("request"); |
| | | header = request.getJSONObject("header"); |
| | | body = request.getJSONObject("body"); |
| | | }else { |
| | | header = response.getJSONObject("header"); |
| | | body = response.getJSONObject("body"); |
| | | } |
| | | |
| | | String msgType = result.getString("msgType"); |
| | | |