正在显示
1 个修改的文件
包含
59 行增加
和
2 行删除
| @@ -91,7 +91,7 @@ public class CommandClient { | @@ -91,7 +91,7 @@ public class CommandClient { | ||
| 91 | head[1]=(byte)0x5C; | 91 | head[1]=(byte)0x5C; |
| 92 | head[2]=(byte)0x4B; | 92 | head[2]=(byte)0x4B; |
| 93 | head[3]=(byte)0x89; | 93 | head[3]=(byte)0x89; |
| 94 | - //消息类型 | 94 | + //消息类型,0x21为gatherInfo 0x22为commandInfo |
| 95 | byte[] mType = new byte[1]; | 95 | byte[] mType = new byte[1]; |
| 96 | mType[0] = (byte)0x22; | 96 | mType[0] = (byte)0x22; |
| 97 | //场站号 | 97 | //场站号 |
| @@ -130,6 +130,63 @@ public class CommandClient { | @@ -130,6 +130,63 @@ public class CommandClient { | ||
| 130 | log.info("文件发送失败"+e.getMessage()); | 130 | log.info("文件发送失败"+e.getMessage()); |
| 131 | } | 131 | } |
| 132 | } | 132 | } |
| 133 | + | ||
| 134 | + private static void sendWithSocket_x21(GatherInfo info,String xmlBody){ | ||
| 135 | + Socket socket =null; | ||
| 136 | + OutputStream op = null; | ||
| 137 | + try { | ||
| 138 | + //ip+端口 | ||
| 139 | + socket = new Socket("118.31.66.166", 17007); | ||
| 140 | + log.info("socket通讯创建连接成功"); | ||
| 141 | + op = socket.getOutputStream(); | ||
| 142 | + //xml字节流 | ||
| 143 | + byte[]xBody =xmlBody.getBytes("GB2312"); | ||
| 144 | + //包头 | ||
| 145 | + byte[] head = new byte[4]; | ||
| 146 | + head[0]=(byte)0xE2; | ||
| 147 | + head[1]=(byte)0x5C; | ||
| 148 | + head[2]=(byte)0x4B; | ||
| 149 | + head[3]=(byte)0x89; | ||
| 150 | + //消息类型,0x21为gatherInfo 0x22为commandInfo | ||
| 151 | + byte[] mType = new byte[1]; | ||
| 152 | + mType[0] = (byte)0x21; | ||
| 153 | + //场站号 | ||
| 154 | + byte[]station =info.getAreaid().getBytes("ASCII"); | ||
| 155 | + //通道号 | ||
| 156 | + byte[]aisle =info.getChnlno().getBytes("ASCII"); | ||
| 157 | + //进出标识 | ||
| 158 | + byte[]eType =info.getIetype().getBytes("ASCII"); | ||
| 159 | + //标识符 | ||
| 160 | + byte[] bwFlag = new byte[4]; | ||
| 161 | + bwFlag[0]=(byte)0x00; | ||
| 162 | + bwFlag[1]=(byte)0x00; | ||
| 163 | + bwFlag[2]=(byte)0x00; | ||
| 164 | + bwFlag[3]=(byte)0x00; | ||
| 165 | + //xml字节流长度 | ||
| 166 | + byte[]xmlLength = intToByte4(xBody.length); | ||
| 167 | + //包尾 | ||
| 168 | + byte[]end = new byte[2]; | ||
| 169 | + end[0]=(byte)0xFF; | ||
| 170 | + end[1]=(byte)0xFF; | ||
| 171 | + System.out.println(); | ||
| 172 | + //总长 4为总长的length | ||
| 173 | + byte [] packge = intToByte4((head.length+xBody.length+mType.length+station.length+aisle.length+eType | ||
| 174 | + .length+bwFlag.length+xmlLength.length+end.length+4)); | ||
| 175 | + byte[]allByte = byteMergerAll(head,packge,mType,station,aisle,eType,bwFlag,xmlLength,xBody,end); | ||
| 176 | + op.write(allByte); | ||
| 177 | + op.flush(); | ||
| 178 | + op.close(); | ||
| 179 | + log.info("发送完毕"); | ||
| 180 | + socket.close(); | ||
| 181 | + } catch (UnknownHostException e) { | ||
| 182 | + e.printStackTrace(); | ||
| 183 | + log.info("创建连接失败"+e.getMessage()); | ||
| 184 | + } catch (IOException e) { | ||
| 185 | + e.printStackTrace(); | ||
| 186 | + log.info("文件发送失败"+e.getMessage()); | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + | ||
| 133 | /** | 190 | /** |
| 134 | * @Param info 卡口采集信息 | 191 | * @Param info 卡口采集信息 |
| 135 | * @Param flag 放行标识 | 192 | * @Param flag 放行标识 |
| @@ -185,7 +242,7 @@ public class CommandClient { | @@ -185,7 +242,7 @@ public class CommandClient { | ||
| 185 | //给三宝的去掉BARCODE,todo:不去掉做个测试 | 242 | //给三宝的去掉BARCODE,todo:不去掉做个测试 |
| 186 | .replace("${BAR_CODE}",info.getBarcode()); | 243 | .replace("${BAR_CODE}",info.getBarcode()); |
| 187 | 244 | ||
| 188 | - sendWithSocket(info,gatherXML); | 245 | + sendWithSocket_x21(info,gatherXML); |
| 189 | } | 246 | } |
| 190 | 247 | ||
| 191 | 248 |
-
请 注册 或 登录 后发表评论