-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNioServerHandler.java
More file actions
44 lines (37 loc) · 1.16 KB
/
Copy pathNioServerHandler.java
File metadata and controls
44 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package lbtech.obj;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
/**
* 实际的业务处理类
*
* @author DF
*
*/
public class NioServerHandler extends SimpleChannelInboundHandler<Person> {
/**
* 日志对象
*/
protected Logger logger = LoggerFactory.getLogger(NioServerHandler.class);
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
// TODO Auto-generated method stub
super.channelRegistered(ctx);
logger.info("--------server channelRegistered-------");
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, Person msg)
throws Exception {
logger.info("client----->收到服务器端消息:name:{},age:{}" , msg.getName(),msg.getAge());
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
super.channelActive(ctx);
ctx.writeAndFlush(new Person("黄登峰",11));
logger.info("--------server channelActive-------");
}
}