socket请求
来源:互联网 发布:网络语言暴力案例图片 编辑:程序博客网 时间:2024/06/05 20:08
public static String sendData2HF(String data,int busType) throws UnknownHostException, IOException {
Log.info(null, SocketUtil.class, "send data to HF>>>>: " + data);
String ip = HFConstant.PBOC_IP;
int port = HFConstant.PBOC_PORT;
Socket socket = new Socket(ip, port);
socket.setSoTimeout(3000);
socket.setTcpNoDelay(true);
OutputStream os = socket.getOutputStream();
InputStream is = socket.getInputStream();
byte[] head = new byte[2];
byte[] body = null;
int busTypes = busType;
if(busTypes==1){
body = new byte[121];
}else if(busTypes==2){
body = new byte[308];
}else if(busTypes==3){
body = new byte[269];
}else if(busTypes==4){
body = new byte[148];
}
try {
byte[] buf = CrbUtil.hexString2Ba(data);
os.write(buf);
os.flush();
BufferedInputStream bufer = new BufferedInputStream(socket.getInputStream());
bufer.read(head);
//前4字节为报文长度
String headlen = CrbUtil.ba2HexString(head);
Log.info(null, SocketUtil.class, "receive data from HF 报文长度(不含报文总长度)<<<: " +headlen);
bufer.read(body);
Log.info(null, SocketUtil.class, "receive data from HF<<<: " + CrbUtil.ba2HexString(body));
return CrbUtil.ba2HexString(head) + CrbUtil.ba2HexString(body);
}catch(Exception e){
e.printStackTrace();
Log.error("", SocketUtil.class, "异常"+e);
} finally {
if (os != null) {
os.close();
}
if (is != null) {
is.close();
}
if (socket != null) {
socket.close();
}
}
return null;
}
Log.info(null, SocketUtil.class, "send data to HF>>>>: " + data);
String ip = HFConstant.PBOC_IP;
int port = HFConstant.PBOC_PORT;
Socket socket = new Socket(ip, port);
socket.setSoTimeout(3000);
socket.setTcpNoDelay(true);
OutputStream os = socket.getOutputStream();
InputStream is = socket.getInputStream();
byte[] head = new byte[2];
byte[] body = null;
int busTypes = busType;
if(busTypes==1){
body = new byte[121];
}else if(busTypes==2){
body = new byte[308];
}else if(busTypes==3){
body = new byte[269];
}else if(busTypes==4){
body = new byte[148];
}
try {
byte[] buf = CrbUtil.hexString2Ba(data);
os.write(buf);
os.flush();
BufferedInputStream bufer = new BufferedInputStream(socket.getInputStream());
bufer.read(head);
//前4字节为报文长度
String headlen = CrbUtil.ba2HexString(head);
Log.info(null, SocketUtil.class, "receive data from HF 报文长度(不含报文总长度)<<<: " +headlen);
bufer.read(body);
Log.info(null, SocketUtil.class, "receive data from HF<<<: " + CrbUtil.ba2HexString(body));
return CrbUtil.ba2HexString(head) + CrbUtil.ba2HexString(body);
}catch(Exception e){
e.printStackTrace();
Log.error("", SocketUtil.class, "异常"+e);
} finally {
if (os != null) {
os.close();
}
if (is != null) {
is.close();
}
if (socket != null) {
socket.close();
}
}
return null;
}
阅读全文
0 0
- Socket请求
- socket请求
- socket 发送http请求
- Flex socket 安全策略请求
- socket 请求测试
- 多线程处理socket请求
- socket发送http请求
- Socket模拟GET请求
- Flex socket 安全策略 请求
- socket模拟http请求
- socket发送请求
- java写socket请求
- PHP Socket请求类
- socket请求银行
- socket模拟http请求
- socket请求接受
- socket模拟http请求
- socket 发送http请求
- Linux 部署thinkphp 遇到的file_put_contents failed to open stream: Permission denied
- java 之 IO 转换流
- 6个编写优质干净代码的技巧
- 点亮细胞231-240
- 支付宝点击付款500
- socket请求
- 各种加密算法比较
- [分治] BZOJ3745: [Coci2015]Norma
- 弹一个底部popwindow
- 点亮细胞241-250
- [BZOJ 2815][ZJOI 2012] 灾难 LCA+拓扑排序(支配树)
- jq表格的增加与删除
- Javascript支持3D游戏,asm.js 和 Emscripten工具,以及和WebAssembly的区别
- Azure 虚拟机新型号发布 — 更具成本效益的数据库工作负载