- 2023-08-31
-
服务器发送一条数据如:
Java代码
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(client.getOutputStream());
out.println("没有查到该数据。");//向客户端发送
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(client.getOutputStream());
out.println("没有查到该数据。");//向客户端发送
out.flush();
然后客户端接收:
Java代码
public BufferedReader recieve(){
//从服务端程序接收数据
InputStreamReader isr=null;
BufferedReader br=null;
try {
isr = new InputStreamReader(server.getInputStream());//这里需要GBK
br = new BufferedReader(isr);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return br;
}
///
BufferedReader br=recieve();
while((message = br.readLine()) != null){
messages+=message;
}
System.out.println("messages="+messages);
public BufferedReader recieve(){
//从服务端程序接收数据
InputStreamReader isr=null;
BufferedReader br=null;
try {
isr = new InputStreamReader(server.getInputStream());//这里需要GBK
br = new BufferedReader(isr);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return br;
}
///
BufferedReader br=recieve();
while((message = br.readLine()) != null){
messages+=message;
}
System.out.println("messages="+messages);
你会发现这样写会是乱码;
应该写成isr = new InputStreamReader(server.getInputStream(),"GBK");
这样就正常显示了。
在服务端默认的编码情况下,JAVA的SOCKET接收需要GBK编码,而C#的接收需要UTF-8编码
iPhone 15 Pro怎么样?值得买
在这个充满期待的金秋时节,苹果公司终于发布了备受瞩目的iPhone15Pro。作为一位深度果粉,我迫不及待地想要与大家分享这款手机的独特魅力。下面,我们将从性能、外观等方面详细介绍iPhone15Pr...
mate40pro参数配置详细(华为Ma
华为Mate40Pro钛媒体注:钛度实验室,是一档针对当前热门科技产品进行评测解读的栏目,秉承“有趣、有态度”的内容解读方式。有态度的深度内容,一键直达!10月22日,华为Mate系列产品迎来了第八代...