package com.casic.client; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; public class ClientHandler extends SimpleChannelInboundHandler<String> { //接收服务端数据&发送数据 @Override protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { System.out.println("客户端接收到的消息: "+msg); ctx.writeAndFlush("12232321"); //完成通信后关闭连接 //ctx.close(); } //和服务器建立连接 @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { //ctx.writeAndFlush("在吗!!!!\\r\\n"); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cause.printStackTrace(); ctx.close(); } }