回退代码

This commit is contained in:
ascrutae 2016-01-26 18:48:12 +08:00
parent 28e686ede7
commit 8e27532579
2 changed files with 2 additions and 21 deletions

View File

@ -43,7 +43,7 @@ public class CollectionServer {
@Override
public void initChannel(io.netty.channel.socket.SocketChannel ch) throws Exception {
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("decoder", new ByteArrayDecoder());
p.addLast("encoder", new ByteArrayEncoder());

View File

@ -12,26 +12,7 @@ public class CollectionServerDataHandler extends SimpleChannelInboundHandler<byt
Thread.currentThread().setName("ServerReceiver");
// 当接受到这条消息的是空则忽略
if (msg != null && msg.length >= 0 && msg.length < Config.DataPackage.MAX_DATA_PACKAGE) {
int start = 0;
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;
}
DataBufferThreadContainer.getDataBufferThread().saveTemporarily(msg);
}
}
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;
}
}