public void channelActive(ChannelHandlerContext ctx) throws Exception {
// Send greeting for a new connection.
//InetAddress.getLocalHost().getHostName() 获取电脑主机名
ctx.write("Welcome to " + InetAddress.getLocalHost().getHostName() + "!\r\n");
ctx.write("It is " + new Date() + " now.\r\n");
ctx.flush();
this.channel = ctx.channel();
//ping(ctx.channel());
}
在写入数据时,如果想成功读取每条数据,必须保证写入的时候要加"\r\n",否则是读不出来的