管道,流程,数据源切换,大屏,测量点位
This commit is contained in:
@ -15,6 +15,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -107,13 +108,36 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
// 处理远程主机强制关闭连接的异常
|
||||
if (cause instanceof IOException) {
|
||||
String message = cause.getMessage();
|
||||
if (message != null && (message.contains("远程主机强迫关闭了一个现有的连接")
|
||||
|| message.contains("Connection reset")
|
||||
|| message.contains("远程主机强迫关闭")
|
||||
|| message.contains("An existing connection was forcibly closed"))) {
|
||||
System.out.println("[" + java.time.LocalDateTime.now() + "] 客户端 [" + ctx.channel().remoteAddress() + "] 已断开连接");
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 异常捕获
|
||||
* 异常捕获 - 只打印简要信息
|
||||
*/
|
||||
System.err.println("[" + java.time.LocalDateTime.now() + "] 服务器处理异常:" + cause.getClass().getSimpleName() + " - " + cause.getMessage());
|
||||
cause.printStackTrace();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当连接断开时调用
|
||||
* @param ctx
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
System.out.println("[" + java.time.LocalDateTime.now() + "] 客户端 [" + ctx.channel().remoteAddress() + "] 连接断开");
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
public static boolean isNumber(String str){
|
||||
String reg = "^[0-9]+(.[0-9]+)?$";
|
||||
return str.matches(reg);
|
||||
|
||||
Reference in New Issue
Block a user