Re: [xSocket-develop] nbc and reading incomming frames with bytes
Status: Inactive
Brought to you by:
grro
|
From: Gregor R. <gre...@go...> - 2008-12-01 21:23:32
|
Hi, ByteBuffer[] is a reference to an array. To print it out you can use the DataConverter.toString(Bytebuffer[]) method. Please note, after printing the data to buffer internal pointers will will modified. If you like to use a String instead of ByteBuffer you can call the readStringByLength(available) instead of readByteBufferByLength(available). See also xSocket's tutorial http://xsocket.sourceforge.net/core/tutorial/V2/TutorialCore.htm Gregor 2008/12/1 <jun...@wp...> > Hi Gregor, > > So If I understand it correctly if I append System.out.println(data); > like this > > if (available > 0) { > ByteBuffer[] data = connection.readByteBufferByLength(available); > System.out.println(data); > return true; > > then I should be able to display all data from the frame that i have > just received. right? > > The Problem is I get this: > > [Ljava.nio.ByteBuffer;@126b249 > > and I'm expecting something like this > > f086010000 > > Is it some kind of pointer/referance? How do I access the real value? Is > there any method like data.getValue etc or I have to split string and so > on? > > regards, > sly > > > > Dnia 1-12-2008 o godz. 16:32 Gregor Roth napisał(a): > > Hi sly, > > > > the method connection.available() return the available bytes. Typically > you will read all available like this: > > > > ////////////////////// > > // > > > > public boolean onData(INonBlockingConnection connection) > > int available = connection.available(); > > > > if (available > 0) { > > ByteBuffer[] data = connection.readByteBufferByLength(available); > > // ... > > return true; > > > > } if (available == -1) { > > // connection is closed > > // ... > > return true; > > } > > } > > > > // > > //////////////////////////////// > > > > If available returns -1 the end of stream is reached. > > > > Gregor > > > > > > > > 2008/12/1 <jun...@wp...> > > > hi, > > > > > > What method should I use to read whole data field of incoming Ethernet > > > frame? I tried readByteBufferByDelimiter but I'm not sure how to > specify > > > delimiter. I want to read all bytes in data field. How to set delimiter > > > to read data until there is no more data? > > > > > > ByteBuffer[] res2 = nbc.readByteBufferByDelimiter(""); > > > System.out.println(res2); > > > > > > regards, > > > sly > > > > > > ---------------------------------------------------- > > > Pstryk i klik. > > > Na Pikeo.pl szybko zamieszczasz swoje najlepsze zdjęcia: > > > > http://klik.wp.pl/?adr=http%3A%2F%2Fpikeo.pl%2Finstances%2Fwp%2Fstrona_01.jsp&sid=557 > > > > > > > > > > > > > ------------------------------------------------------------------------- > > > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > > > Build the coolest Linux based applications with Moblin SDK & win great > prizes > > > Grand prize is a trip for two to an Open Source event anywhere in the > world > > > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > > > _______________________________________________ > > > xSocket-develop mailing list > > > xSo...@li... > > > https://lists.sourceforge.net/lists/listinfo/xsocket-develop > > > > > > > ---------------------------------------------------- > Pstryk i klik. > Na Pikeo.pl szybko zamieszczasz swoje najlepsze zdjęcia: > > http://klik.wp.pl/?adr=http%3A%2F%2Fpikeo.pl%2Finstances%2Fwp%2Fstrona_01.jsp&sid=557 > > > |