Posted September 11, 20232 yr 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.
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.