NioDatagramChannel UDP miss data comparing with Mina

Angela angelatao.py at 163.com
Thu Sep 8 06:24:11 EDT 2011


Hi,
I have changed my project based on Mina to Netty. But I've found a problem(I
am not sure it is or not) which is using
org.apache.mina.transport.socket.nio.NioDatagramAcceptor and MyDecoder
extends ProtocolDecoderAdapter receiving broadcast by 500kb/s from our test
upd packet sender program the size of received datas is the same with the
sender sended, but I use NioDatagramChannelFactory and mydecoder extends
FrameDecoder missed lots of datas.

The upd package is like this:
typedef struct HeaderGroup{
	unsigned char cDataID;
	unsigned char cNoOfItems;
	short sTtlPktLen;
	unsigned long lSeqNo;
}SHeaderGroup;
**********************************************
                     broadcast body
**********************************************
typedef struct PriceGroup{
	unsigned char cPrcHeader;
	unsigned char cGroupLen;
	unsigned short sStockCd;
	long lOpenField;
	long lHighField;
	long lLowField;
}SPriceGroup;

Firstly, I need decode the headergroup to get the NoOfItems of the
PriceGroup, then I can decode the pricegroup iterately. MyDecoder likes
below:
protected Object decode(ChannelHandlerContext ctx, Channel channel,
ChannelBuffer in) throws Exception {
			List<AbstractStd3Group> groups = new ArrayList<AbstractStd3Group>();
		
			if (in.readableBytes() < 8) {
				System.out.println("checkpoint(Std3DecoderState.READ_HEAD");
				return null;
			} else{
				in.markReaderIndex();
				srcID = in.readUnsignedByte();
				items = in.readUnsignedByte();
				in.skipBytes(2);
				seqNO = in.readUnsignedInt();
				System.out.println("Source Group count " + (srccount++) + " srcID " +
srcID + " items: " + items);;
			}
			
			if (in.readableBytes() < (3 * items)) {
				in.resetReaderIndex();
				return null;
			}
		
		
		int pos;
		for (short i = 0; i < items; i++) {
			pos = in.readerIndex();
			grpID = in.readUnsignedByte();//in.getUnsigned();
			length = in.readUnsignedByte();
//			in.resetReaderIndex();//in.reset();
			in.readerIndex(pos);
			if (in.readableBytes() < length){
				in.resetReaderIndex();
				return null;
			}
			
			index++;
			
			/*IStd3Decoder<? extends AbstractStd3Group> decoder =
getStd3Decoder(srcID,grpID);
			if(decoder == null) {
				in.skipBytes(length);
			} else {
				//head info
				HeadInfoImpl headInfo = new HeadInfoImpl();
				headInfo.sourceID = srcID;
				headInfo.itemCount = items;
				headInfo.sequenceNO = seqNO;
				headInfo.groupID = grpID;
				headInfo.itemIndex = i;
				
				ChannelBuffer itemIoBuffer = in.readSlice(length);
				
				AbstractStd3Group group = decoder.decode(headInfo, itemIoBuffer);
				
//				return group;
				//if(group != null) {
					groups.add(group);
				//}
			
			}*/
			
			in.skipBytes(length);
		}
		
			return groups;
		
	}

The config of mina and netty are the same. Is there anybody know how to fix
this? Thanks a lot...

--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/NioDatagramChannel-UDP-miss-data-comparing-with-Mina-tp6771200p6771200.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list