问题描述
我正在使用 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 (将#修改为@)