Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

这个位置似乎是错的. #5

Closed
HengCC opened this issue Oct 11, 2017 · 5 comments
Closed

这个位置似乎是错的. #5

HengCC opened this issue Oct 11, 2017 · 5 comments

Comments

@HengCC
Copy link

HengCC commented Oct 11, 2017

msgHeader.setSubPackageSeq(this.parseIntFromBytes(data, 12, 2));

是否应该改成

msgHeader.setSubPackageSeq(this.parseIntFromBytes(data, 14, 2));
@xxnKevin
Copy link

xxnKevin commented May 7, 2018

我也觉得这里应该是 msgHeader.setSubPackageSeq(this.parseIntFromBytes(data, 14, 2));

@hylexus
Copy link
Owner

hylexus commented Feb 27, 2019

已修改

@hylexus hylexus closed this as completed Feb 27, 2019
@631292865
Copy link

请问为什么导入maven工程,运行服务器后,用网络调试助手向服务器发送十六进制内容,服务器控制台没能显示终端鉴权、终端注册、位置信息汇报等具体信息,只是显示了调用的new Decoder4LoggingOnly()。刚接触netty,很多小问题,望见谅

@hylexus
Copy link
Owner

hylexus commented May 4, 2019

@631292865 麻烦把具体报文贴出来,我抽空看看。

@631292865
Copy link

@631292865 麻烦把具体报文贴出来,我抽空看看。
将你的工程导入后,用网络调试助手向服务器发送十六进制的鉴权包,服务器控制台没能显示出"<<<<<[终端鉴权],phone={},flowid={}"之类的,只能显示出"ip={},hex = {}",也就是只调用了下面的ch.pipeline().addLast(new Decoder4LoggingOnly()); ,没有调用TCPSeverHandler()里的channelread()方法,请问为什么呢??刚接触netty,问题很多,望见谅,谢谢
private void bind() throws Exception {
this.bossGroup = new NioEventLoopGroup();
this.workerGroup = new NioEventLoopGroup();
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup)//
.channel(NioServerSocketChannel.class) //
.childHandler(new ChannelInitializer() { //
@OverRide
public void initChannel(SocketChannel ch) throws Exception {
// 客户端发呆分钟后,服务器主动断开连接
ch.pipeline().addLast("idleStateHandler",
new IdleStateHandler(TPMSConsts.tcp_client_idle_minutes, 0, 0, TimeUnit.MINUTES));

					ch.pipeline().addLast(new Decoder4LoggingOnly());
					
					// 1024表示单条消息的最大长度,解码器在查找分隔符的时候,达到该长度还没找到的话会抛异常
					ch.pipeline().addLast(
							new DelimiterBasedFrameDecoder(1024, Unpooled.copiedBuffer(new byte[] { 0x7e }),
									Unpooled.copiedBuffer(new byte[] { 0x7e, 0x7e })));
					 // 分隔符解码方式
					//ch.pipeline().addLast(new PackageDataDecoder());
					ch.pipeline().addLast(new TCPServerHandler());//无法调用TCPSeverHandler()里的channelread()???
				}
			}).option(ChannelOption.SO_BACKLOG, 128) 
			.childOption(ChannelOption.SO_KEEPALIVE, true);

	this.log.info("TCP服务启动完毕,port={}", this.port);
	ChannelFuture channelFuture = serverBootstrap.bind(port).sync();
	channelFuture.channel().closeFuture().sync();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants