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.

Featured Replies

Posted

Hello everyone.

I've been working on a server to client packet recently. So I've done this:

 

public class SendBipedCostumes implements IMessage {

public Quintet<Float,String,String,Float,Float>[] modelsDeclaration;

public SendBipedCostumes() { }

    public SendBipedCostumes(Quintet<Float,String,String,Float,Float>[] modelsDeclaration) {
    	this.modelsDeclaration = modelsDeclaration;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
    	System.out.println("Reading...");
        int size = Integer.parseInt(ByteBufUtils.readUTF8String(buf));
        ArrayList<Quintet<Float,String,String,Float,Float>> models = new ArrayList<Quintet<Float,String,String,Float,Float>>(); // new Object[size];
        for (int i = 0; i < size; i++) 
        	models.add(Quintet.with(buf.readFloat(), ByteBufUtils.readUTF8String(buf), ByteBufUtils.readUTF8String(buf), buf.readFloat(), buf.readFloat()));
        this.modelsDeclaration = models.toArray(new Quintet[models.size()]);
    	System.out.println("Read.");
    }

    @Override
    public void toBytes(ByteBuf buf) {
    	System.out.println("Writing...");
    	ByteBufUtils.writeUTF8String(buf, String.valueOf(this.modelsDeclaration.length));
        for (Quintet<Float,String,String,Float,Float> v : this.modelsDeclaration) {
        	System.out.println(String.valueOf(v.getValue0()).length());
            //ByteBufUtils.writeUTF8String(buf, String.valueOf(v.getValue0()));
            buf.writeFloat(v.getValue0());
        	System.out.println(v.getValue1().length());
            ByteBufUtils.writeUTF8String(buf, v.getValue1());
        	System.out.println(v.getValue2().length());
            ByteBufUtils.writeUTF8String(buf, v.getValue2());
        	System.out.println(String.valueOf(v.getValue3()).length());
            //ByteBufUtils.writeUTF8String(buf, String.valueOf(v.getValue3()));
        	buf.writeFloat(v.getValue3());
        	System.out.println(String.valueOf(v.getValue4()).length());
            //ByteBufUtils.writeUTF8String(buf, String.valueOf(v.getValue4()));
        	buf.writeFloat(v.getValue4());
        }
      	System.out.println("Written.");
    }
    
    
    public static class Handler implements IMessageHandler<SendBipedCostumes, IMessage> {
        
        @Override
        public IMessage onMessage(SendBipedCostumes m, MessageContext ctx) {
        	LyokoCraftMod.proxy.sendBipedCostumeHandler(m, ctx);
        	return null;
        }
        
}

 

It works perfectly in single player, the handler is executed with all the data it needs.

However, when I try to do it on a server, when the packet is sent, the client gets an error :

 

Internal Exception: io.netty.handler.codec.DecoderException:

java.IOException: The received string length is longer than maximum allowed (25 > 20)

 

The server however just doesn't say anything.

The problem is that no parameter is 25 bytes long. Actually they all are pretty small. The longest one is 19 simple characters long.

I don't know anything about netty, but I figured out that the problem occurs when the client tries to understand the raw packet, but it keeps failing because 20 is an hardcoded maximal value.

 

Do you know how I could find a way out of that problem?

Thanks in advance!

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.