67,513
社区成员
发帖
与我相关
我的任务
分享
public class ServerStringHandler extends ChannelInboundHandlerAdapter {
//全系统公共静太变量, 所有代码中都可以用同一个容器, 你也可以定义在别的地方.
public static AbstractApplicationContext APP_CONTEXT = new ClassPathXmlApplicationContext("applicationContext.xml");
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ByteBuf result = (ByteBuf) msg;
byte[] res = new byte[result.readableBytes()];
result = result.readBytes(res);
String str = Tools.bytesToHexString(res);
// 判断str是拉绳传感器还是陀螺仪的
if ("02".equals(str.substring(0, 2))) {
InsertDate da = (InsertDate) APP_CONTEXT.getBean("goodsServiced");
da.insetshift(str);
ioc.close();
}
result.release();
}
}