| | |
| | | public void channelInactive(ChannelHandlerContext ctx) throws Exception { |
| | | //断开连接 |
| | | System.out.println("客户端断开连接:" + ctx.channel()); |
| | | //用户离线状态 |
| | | String name = ChannelSupervise.findName(ctx.channel().id().asShortText()); |
| | | String num="0"; |
| | | webSocketHandler.suserService.updateUser(num,name); |
| | | ChannelSupervise.removeChannel(ctx.channel()); |
| | | } |
| | | |
| | |
| | | } |
| | | // 返回应答消息 |
| | | String request = ((TextWebSocketFrame) frame).text(); |
| | | String substring1 = request.substring(0, 2); |
| | | //把用户信息添加到通道里 |
| | | ChannelSupervise.addChannel(ctx.channel(),request); |
| | | //用户在线状态 |
| | | if(substring1.equals("登录")){ |
| | | String online="1"; |
| | | String substring = request.substring(0, request.length()); |
| | | System.out.println(substring); |
| | | String[] split = substring.split(",");//以逗号分割 |
| | | this.on=split[1]; |
| | | webSocketHandler.suserService.updateUser(online,this.on); |
| | | } |
| | | //用户离线状态 |
| | | else if (substring1.equals("退出")){ |
| | | String online="0"; |
| | | String substring = request.substring(0, request.length()); |
| | | System.out.println(substring); |
| | | String[] split = substring.split(",");//以逗号分割 |
| | | this.on=split[1]; |
| | | webSocketHandler.suserService.updateUser(online,this.on); |
| | | webSocketHandler.channelInactive(ctx); |
| | | } |
| | | this.on=request; |
| | | String num="1"; |
| | | webSocketHandler.suserService.updateUser(num,request); |
| | | TextWebSocketFrame tws = new TextWebSocketFrame(new Date().toString() |
| | | + ctx.channel().id() + ":" + ctx.channel()); |
| | | // 返回【谁发的发给谁】 |