socket读不到流的结尾,直到报Read timed out
代码:
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)
相关推荐
pip安装第三方包时出现socket.timeout: The read operation timed out超时问题
pip安装第三方包时出现socket.timeout: The read operation timed out超时问题 在cmd中使用pip安装第三方包时有时候会出现超时问题,这个问题的原因就是网络连接速度过慢。有的时候可能不是你的电脑网速过慢而是由于下载的网站是外网因此受到了网速的限制。 我们有两个方法解决这个问题: 1.采用镜像服务器 这里推荐用清华大学的镜像服务器,速度十分稳定 在C:\Users\你的用户名 里新建pip文件夹,再建pip.ini 例如C:\Users\你的用户名\pip\pip.ini pip.ini 中写入: [global] index-url = https
pip install出现socket.timeout: The read operation timed out的解决方案
本文主要介绍了pip install出现socket.timeout: The read operation timed out的解决方案,希望能对新手有所帮助。需要说明的是下图中的示例为lxml,但是其他Python库的解决方案也是一致的。 文章目录 1. 问题描述 2. 解决方案 2.1 方案一 2.2 方案二
C#以流方式读socket超时设置的实例
主要为大家详细介绍了C#以流方式读socket超时设置的实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
java.net.SocketTimeoutException: Receive timed out
NULL 博文链接:https://mymobile.iteye.com/blog/1853228
Socket中InputStream的read方法的阻塞特性
NULL 博文链接:https://superherosk123.iteye.com/blog/611933


Java SE
