JAVA(12)-netty-server-client 连接过程与消息传递

1.server- clients 通信过程
2.消息的生成过程


1.server- clients 通信过程
 1.1.ServerFrame 窗口启动, Server 服务器端启动

  1.2.ClientFrame 窗口启动 ,Client 客户端启动

  正常连接后,client 会在channelRead0() 里收到一条消息 ClientJoinMsg

  1.Client : client channelActive()
               send msg ClientJoinMsg

  2.Server:激活通道+收客户端消息 channelRead()
  3.Server :收消息+发消息给所有的客户端

  4.Clients: channelRead read
                ClientJoinMsg

2.消息的使用。
   首先要定义消息类型,之后写消息体和消息的handle()函数,测试msg写的对不对,最后考虑在哪发送。

2.1定义消息类型:MsgType :msgNew1 
2.2 写消息体的实现类New1Msg
2.3测试消息类写的对不对 New1Msg
2.4触发消息体 Client.INSTANCE.send(new New1Msg( ));
与mfc,afxmessagemap不同,触发和循环都得自己写。

猜你喜欢

转载自blog.csdn.net/aggie4628/article/details/107282254
今日推荐