如何解决使用 BufferedReader 接收 TCP 数据包时超时
我正在使用 BufferedReader 在我的客户端代码中的特定端口上读取 TCP 数据包。但我的问题是超过 5000 个数据包,350 个数据包超时在 15 分钟的时间范围内。我在 stackoverflow 中检查了其他答案,但我的问题没有解决。
我如何克服这个超时问题以及它为什么会发生。请帮我解决这个问题。下面是我读取数据包的客户端代码,程序在JAVA中。
注意:数据包长度为 30。
private void listen() throws Exception {
ByteBuffer byteBuffer = null;
DateTimeFormatter dtf = null;
LocalDateTime now = null;
int cnt=0;
String data = null;
String[] res = null;
String[] res1 = null;
String clientAddress="";
while(true){
Socket client = this.server.accept();
clientAddress = "";
clientAddress = client.getInetAddress().getHostAddress();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
byteBuffer = ByteBuffer.allocate( 10240 );
while ( (data = in.readLine()) != null ) {
try{
dtf=DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
now=LocalDateTime.now();
System.out.println("\r\n"+dtf.format(now)+":: " + clientAddress + ": " + data);
}catch(Exception s){
s.printStackTrace();
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。