Posted August 26, 201411 yr Hello. I'm trying to use SimpleNetworkWrapper, according to this and some other manuals. On my client side i have: public void preInit(FMLPreInitializationEvent e) { network = NetworkRegistry.INSTANCE.newSimpleChannel("test"); network.registerMessage(Message.FromServerHandler.class, Message.class, 0, Side.CLIENT); } On my server side i have: public void preInit(FMLPreInitializationEvent e) { network = NetworkRegistry.INSTANCE.newSimpleChannel("test"); network.registerMessage(Message.FromClientHandler.class, Message.class, 0, Side.SERVER); } Message.class: package info.deseven.test.event; import io.netty.buffer.ByteBuf; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; public class Message implements IMessage { private String text; public Message(String text) { this.text = text; } @Override public void fromBytes(ByteBuf buf) { text = ByteBufUtils.readUTF8String(buf); // this class is very useful in general for writing more complex objects } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, text); } public static class FromServerHandler implements IMessageHandler<Message, IMessage> { @Override public IMessage onMessage(Message message, MessageContext ctx) { System.out.println(String.format("Received %s", message.text)); return null; // no response in this case } } public static class FromClientHandler implements IMessageHandler<Message, IMessage> { @Override public IMessage onMessage(Message message, MessageContext ctx) { System.out.println(String.format("Received %s from %s", message.text, ctx.getServerHandler().playerEntity.getDisplayName()));; return null; // no response in this case } } } So, i'm trying to send the message to the client right after login, like that: public void onEvent(PlayerLoggedInEvent event) { System.out.println("[test] " + event.player.getDisplayName() + " connected"); System.out.println("[test] sending 'test' to " + event.player.getDisplayName()); ServerProxy.network.sendTo(new Message("test"), (EntityPlayerMP) event.player); } But on the client i'm getting this: [01:05:00] [Client thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught io.netty.handler.codec.DecoderException: java.lang.InstantiationException: info.deseven.test.event.Message Can anyone help?
August 26, 201411 yr Author Oh, right... Added public Message() {} to the Message.class and that's all. Thank you!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.