日期:2014-05-20 浏览次数:20927 次
try {
s.setSoTimeout(6000 * 5);//设定超时时间
input = new DataInputStream(new BufferedInputStream(s.getInputStream()));
// 头两个字节表示报文总(报文头+数据内容)长度
byte[] header = new byte[2];//2字节长的报头
int len = 0;
while((len = input.read(header)) != -1){
break;
}
int msgLen = Integer.parseInt(IsoUtil.hexString(header), 16);
System.out.println("megLen=" + msgLen);
//按每次两个字节读取
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int start = 0;
while((len = input.read(header, 0, 2)) != -1){
System.out.println("in while, len=" + len);
start += len;
baos.write(header);
}
System.out.println("start=" + start);
//读取全部报文
byte[] msg = new byte[start];
msg = baos.toByteArray();
System.out.println("hex=" + IsoUtil.hexString(msg));//报文内容
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
~~~~~~~接受报文开始~~~~~~
from ip:/192.168.1.111:2059
Len=2
hex=003C
megLen=60
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
in while, len=2
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at java.io.DataInputStream.read(Unknown Source)
at com.hyt.pos.PosReceiver.run(PosReceiver.java:52)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)