Re: [xSocket-develop] Connection closed after 2 packets
Status: Inactive
Brought to you by:
grro
|
From: Gregor R. <gre...@go...> - 2008-12-12 17:47:55
|
Hi Jens, data will be segmented on the network level. If the onData() method is called, it is not predictable how many bytes will be received. This causes that each NonBlockingConnection read method will throw a BufferUnderflowException, if not enough data is available An example for reading mutlipart records can be found in the tutorial chapter 13 -16: http://xsocket.sourceforge.net/core/tutorial/V2/TutorialCore.htm Gregor 2008/12/12 Jens Ramhorst <jen...@ju...> > Hello, > I have a big problem. > I am new to xSocket and my written Server close every connection after > two packets without reason. > The packagesize is equal. > Example: > The first 2 bytes of data are the length of all data, that the client > send. In this example 1492 bytes. With the nbc.readByte-Method i try to > read all 1492 bytes. But after 2 packages (for e.g. 500 bytes) the Sever > close the connection and System.out.println is never reached. > I looked with wireshark and after the first packege the server send ACK, > after the second the server send ACK and FIN,ACK. > The Code: > public boolean onData(INonBlockingConnection nbc) throws IOException, > BufferUnderflowException, ClosedChannelException, > MaxReadSizeExceededException { > byte[] lengthArray = new byte[2]; > for (int i=0; i<2; i++) { > lengthArray[i] = > ByteKit.fromUnsignedInt(nbc.readByte()); // Reads the complete length of > data the client send > } > int length = > ByteKit.chartoInt((byte)0,(byte)0,lengthArray[0],lengthArray[1]); // The > length of data > byte dataArray[] = new byte[length]; > dataArray = nbc.readBytesByLength(length); // Read all data > in array > System.out.println("Done"!); // Never reached > } > > Has anybody an idea. > Best regards. > Jens > > > ------------------------------------------------------------------------------ > SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. > The future of the web can't happen without you. Join us at MIX09 to help > pave the way to the Next Web now. Learn more and register at > > http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ > _______________________________________________ > xSocket-develop mailing list > xSo...@li... > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > |