Jump to content

Help!!!1.19.4 About the issue of channel packet string


mohuang369

Recommended Posts

Please Help!!!!

public static void encode(MessageFromClient msg, FriendlyByteBuf buf) {
//        buf.writeString(msg.message);
        LOGGER.info("here:"+msg.message);
        buf.writeUtf(msg.message);
//        try {
//            buf.writeBytes(msg.message.getBytes("utf-8"));
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
    }

I use this method to send string data to the server,this is correct for client side printing

{"id":"Manager","formPlug":"Manager","toPlug":"Trmenu","type":3,"playerName":"mohuangNPC","uuid":"85bfd415-4262-352e-ab70-e0f08c077db1","msg":"trmenu open Main"}

But what the server receives is:

SOH{"id":"Manager","formPlug":"Manager","toPlug":"Trmenu","type":3,"playerName":"mohuangNPC","uuid":"85bfd415-4262-352e-ab70-e0f08c077db1","msg":"trmenu open Main"

The prefix is SOH,I searched for information and found that it belongs to ascii,and the symbol is missing at the end "}"

This is the server receiving code:

 public void onPluginMessageReceived(String channel, Player player, byte[] message) {
        ByteArrayDataInput in = ByteStreams.newDataInput(message);
        String subchannel = in.readUTF();
        Logger.debug(subchannel);
        String[] split = subchannel.split("\001", -1);
        if(split.length == 2){
            subchannel = split[1];
        }else{
            subchannel = split[0];
        }
        String[] split1 = subchannel.split("\u0001", -1);
        if(split1.length == 2){
            subchannel = split1[1];
        }else{
            subchannel = split1[0];
        }
        Logger.debug(subchannel);
        subchannel = subchannel + "}";
        Logger.debug(subchannel);
}

I now manually remove the prefix and add the suffix,but I want to know what is the reason for this!

If anyone knows please help me, I would be very grateful.

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.