1

I'm new to Javolution and C/C++ . But I really like it so far and I think makes the code much cleaner.

I have been playing with the UDP example that can be found here http://javolution.org/target/site/apidocs/javolution/io/Struct.html

It is working well except when I use UTF8String. Is this normal.

So for I have a Struct like this

public class UserTest extends Struct
{
    public Unsigned8 age  = new Unsigned8();
    public UTF8String name  = new UTF8String(8);
}

then i have another class that sends via udp the struct

ByteBuffer buf = ByteBuffer.allocate(1400);
DatagramChannel channel = DatagramChannel.open(); 
channel.connect(new InetSocketAddress("localhost", 54300));
buf.clear();
buf.put(userStruct.getByteBuffer());
buf.flip();
channel.write(buf);

Now on the otherside of the connection I have the following

channel.receive(buffer);
buffer.flip();
userStruct.getByteBuffer().put(buffer);
System.out.println("Do I have a name >>>> "+ userStruct.name.get());
System.out.println("Do I have an age >>>> "+ userStruct.age.get());

Now this doesn't work but I remove name and just keep age then I can retrieve the value of age?

Is it possible to send String via Struct over the network?

Thank you, Anthony

  • This seems most unwise to me. The Javolution `Struct` implementation is meant to match the native structure format of the particular platform you're running on. It's not meant to be a universal format that has meaning across implementations. UDP protocols should be defined at the byte level and should not rely on the specifics of a single implementation or platform. – David Schwartz Sep 30 '13 at 19:48
  • Thank you for your answer. But it seemed like a nice way to transfer bytes and not do anything with serialization. – user1313322 Oct 01 '13 at 08:28
  • If (since) you don't want to use serialization, checkout ByteBuffer, or Nettys ByteBuf, http://netty.io/4.0/api/io/netty/buffer/ByteBuf.html – claj Jan 19 '14 at 18:37

0 Answers0