项目场景:
JAVA 使用NETTY框架建立socket数据通讯问题描述:
服务端将定义好的字符串,转HEX值,回复到客户端,客户端将字符串转码解析后中文乱码String strTo16 = HexUtils.strTo16(json.toString());
public static String strTo16(String s) {
String str = "";
for (int i = 0; i < s.length(); i++) {
int ch = (int) s.charAt(i);
String s4 = Integer.toHexString(ch);
str = str + s4;
}
return str;
}
服务端回复
ByteBuf resp = Unpooled.copiedBuffer(HexUtils.HexString2Buf(strTo16 )