|
|
@@ -1,6 +1,7 @@ |
|
|
|
package com.iformall.haikang.netty; |
|
|
|
|
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.Map; |
|
|
@@ -50,6 +51,15 @@ public class NioSocketHandler extends SimpleChannelInboundHandler<String>{ |
|
|
|
String clientId = ctx.channel().id().asShortText(); |
|
|
|
log.info("netty tcp 接收到用户id为"+clientId+"的消息: " + msg); |
|
|
|
cctx = ctx; |
|
|
|
|
|
|
|
//此处是弥补处理,客户端断开后重连 |
|
|
|
if (null == peopleNumberFactory.handlerList) { |
|
|
|
peopleNumberFactory.handlerList = new ArrayList<NioSocketHandler>(); |
|
|
|
} |
|
|
|
if (!peopleNumberFactory.handlerList.contains(this)) { |
|
|
|
peopleNumberFactory.handlerList.add(this); |
|
|
|
} |
|
|
|
|
|
|
|
// 应答报文,根据要求应答 |
|
|
|
String repeak = msg; |
|
|
|
handleMessage(ctx,msg); |
|
|
@@ -64,10 +74,18 @@ public class NioSocketHandler extends SimpleChannelInboundHandler<String>{ |
|
|
|
cause.printStackTrace(); |
|
|
|
ctx.close(); |
|
|
|
cctx = null; |
|
|
|
log.info(ctx+" exceptionCaught"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//编号2代表需要等待时长,编号3代表当前排队人数,编号4代表当前场内出租车,编号5代表在途出租车 |
|
|
|
@Override |
|
|
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception { |
|
|
|
super.channelInactive(ctx); |
|
|
|
ctx.close(); |
|
|
|
cctx = null; |
|
|
|
log.info(ctx+" channelInactive"); |
|
|
|
} |
|
|
|
|
|
|
|
//编号2代表需要等待时长,编号3代表当前排队人数,编号4代表当前场内出租车,编号5代表在途出租车 |
|
|
|
private static final int[] types = new int[] {2,3,4,5}; |
|
|
|
|
|
|
|
private void handleMessage(ChannelHandlerContext ctx,String message) { |
|
|
|