http传输过程中会将中文编码改为"ISO8859-1"
so:
try { String newcs=new String(response.getBytes("ISO8859-1"),"UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); }
socket编程时字节长度的问题
so:
int msg_len = msg == null ? 0 : msg.getBytes(StandardCharsets.UTF_8).length; DatagramPacket dPacket = new DatagramPacket(msg.getBytes(StandardCharsets.UTF_8), msg_len,local, SERVER_PORT);