| | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | } |