|
|
|
package com.crossoverjie.cim.client.handle;
|
|
|
|
|
|
|
|
import com.crossoverjie.cim.client.service.EchoService;
|
|
|
|
import com.crossoverjie.cim.client.service.ShutDownMsg;
|
|
|
|
import com.crossoverjie.cim.client.service.impl.EchoServiceImpl;
|
|
|
|
import com.crossoverjie.cim.client.thread.ReConnectJob;
|
|
|
|
import com.crossoverjie.cim.client.util.SpringBeanFactory;
|
|
|
|
import com.crossoverjie.cim.common.constant.Constants;
|
|
...
|
...
|
@@ -41,6 +43,8 @@ public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProt |
|
|
|
|
|
|
|
private ShutDownMsg shutDownMsg ;
|
|
|
|
|
|
|
|
private EchoService echoService ;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
|
...
|
...
|
@@ -68,7 +72,6 @@ public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProt |
|
|
|
|
|
|
|
@Override
|
|
|
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
|
|
|
|
|
|
|
//客户端和服务端建立连接时调用
|
|
|
|
LOGGER.info("cim server connect success!");
|
|
|
|
}
|
|
...
|
...
|
@@ -95,6 +98,10 @@ public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProt |
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void channelRead0(ChannelHandlerContext ctx, CIMResponseProto.CIMResProtocol msg) throws Exception {
|
|
|
|
if (echoService == null){
|
|
|
|
echoService = SpringBeanFactory.getBean(EchoServiceImpl.class) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//心跳更新时间
|
|
|
|
if (msg.getType() == Constants.CommandType.PING){
|
|
...
|
...
|
@@ -108,7 +115,7 @@ public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProt |
|
|
|
|
|
|
|
//将消息中的 emoji 表情格式化为 Unicode 编码以便在终端可以显示
|
|
|
|
String response = EmojiParser.parseToUnicode(msg.getResMsg());
|
|
|
|
System.out.println(response);
|
|
|
|
echoService.echo(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
...
|
...
|
|