提交 8e275325 编写于 作者: A ascrutae

回退代码

上级 28e686ed
...@@ -43,7 +43,7 @@ public class CollectionServer { ...@@ -43,7 +43,7 @@ public class CollectionServer {
@Override @Override
public void initChannel(io.netty.channel.socket.SocketChannel ch) throws Exception { public void initChannel(io.netty.channel.socket.SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline(); ChannelPipeline p = ch.pipeline();
p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 0)); p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0,4));
p.addLast("frameEncoder", new LengthFieldPrepender(4)); p.addLast("frameEncoder", new LengthFieldPrepender(4));
p.addLast("decoder", new ByteArrayDecoder()); p.addLast("decoder", new ByteArrayDecoder());
p.addLast("encoder", new ByteArrayEncoder()); p.addLast("encoder", new ByteArrayEncoder());
......
...@@ -12,26 +12,7 @@ public class CollectionServerDataHandler extends SimpleChannelInboundHandler<byt ...@@ -12,26 +12,7 @@ public class CollectionServerDataHandler extends SimpleChannelInboundHandler<byt
Thread.currentThread().setName("ServerReceiver"); Thread.currentThread().setName("ServerReceiver");
// 当接受到这条消息的是空,则忽略 // 当接受到这条消息的是空,则忽略
if (msg != null && msg.length >= 0 && msg.length < Config.DataPackage.MAX_DATA_PACKAGE) { if (msg != null && msg.length >= 0 && msg.length < Config.DataPackage.MAX_DATA_PACKAGE) {
int start = 0; DataBufferThreadContainer.getDataBufferThread().saveTemporarily(msg);
int end;
while (start < msg.length) {
int length = bytesToInt(msg, start);
start = start + 4;
end = start + length;
byte[] dest = new byte[length];
System.arraycopy(msg, start, dest, 0, length);
DataBufferThreadContainer.getDataBufferThread().saveTemporarily(dest);
start = end;
}
} }
} }
public static int bytesToInt(byte[] ary, int offset) {
int value;
value = (int) ((ary[offset + 3] & 0xFF)
| ((ary[offset + 2] << 8) & 0xFF00)
| ((ary[offset + 1] << 16) & 0xFF0000)
| ((ary[offset] << 24) & 0xFF000000));
return value;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册