我正在尝试发送一些ASCII
代码,我不确定我需要什么样的UTF
或者发送它的正确方法是什么(它开始发送数字,正常字符串,并且工作正常......但ASCII
读取.readUTF()
给出了编码String
)提前谢谢!
服务器
private void sendData() throws IOException {
ObjectOutputStream entityData;
// El cliente ya se ha conectado
OutputStream out = cliente.getOutputStream();
/**
* Para poder enviar tipos primitivos (incluido String) necesitamos una
* clase de conveniencia como DataOutputStream en lugar de OutputStream
* (que solo permite el envio de bytes)
*/
String s = "(_̅_̅_̅_̅_̅м̅a̅я̅i̅j̅u̅a̅n̅a̅_̅_̅_̅ ()ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็";
OutputStreamWriter osw = new OutputStreamWriter(out, StandardCharsets.UTF_16);
osw.write(s,0,s.length());
//String butterfly = "Ƹ̵̡Ӝ̵̨̄Ʒ";
}
客户端
private void receiveData() throws IOException {
InputStream input = socket.getInputStream();
//data = new DataInputStream(input);
InputStreamReader isr = new InputStreamReader(input, StandardCharsets.UTF_16) ;
BufferedReader br = new BufferedReader(isr);
// wait for response
String responseLine = br.readLine();
System.out.println(responseLine);
/*entityData = new ObjectInputStream(input);
String s = entityData.readUTF();
System.out.println(s);*/
}