代码调整
This commit is contained in:
@@ -459,7 +459,7 @@ public class SocketDevResponseService {
|
||||
double diff = Math.abs(num1 - num2);
|
||||
double larger = Math.max(num1, num2);
|
||||
if(DicDataEnum.V.getCode().equals(type)){
|
||||
return BigDecimal.valueOf(diff / larger).setScale(4, RoundingMode.HALF_UP);
|
||||
return BigDecimal.valueOf(num1 - num2).setScale(4, RoundingMode.HALF_UP);
|
||||
}else {
|
||||
return BigDecimal.valueOf(diff / larger).multiply(BigDecimal.valueOf(100)).setScale(4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
public void handlerRemoved(ChannelHandlerContext ctx){
|
||||
// 假设用户 ID 是从某个地方获取的,这里简单示例为 "userId"
|
||||
System.out.println("weoSocket客户端退出: " + ctx.channel().id());
|
||||
WebServiceManager.removeChannel(ctx.channel().id().toString());
|
||||
@@ -116,7 +116,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
System.out.println("weoSocket断线" + ctx.channel().id());
|
||||
ctx.close();
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class WebSocketInitializer extends ChannelInitializer<SocketChannel> {
|
||||
* 这个时候我们只需要访问 ws://127.0.0.1:7777/hello 就可以了
|
||||
* 这个handler是将http协议升级为websocket 并且使用 101 作为响应码
|
||||
* */
|
||||
pipeline.addLast(new IdleStateHandler(10, -1, -1, TimeUnit.SECONDS));
|
||||
pipeline.addLast(new IdleStateHandler(13, 0, 0, TimeUnit.SECONDS));
|
||||
pipeline.addLast(new WebSocketHandler());
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler("/hello"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user