Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.7.10] SimpleNetworkWrapper problems

Featured Replies

Posted

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?

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.