Jump to content

[1.7.10] SimpleNetworkWrapper problems


de7

Recommended Posts

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?

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.