【发布时间】:2018-04-08 12:16:58
【问题描述】:
我有一个将字符串发送到套接字客户端的服务器。当我尝试从客户端获取字符串的内容时,它不会读取它。 服务器发送方式:
output.write(res); output.flush(); // I checked res content and it is all good
这是客户端接收:
public class Client {
public static void main(String[] args) throws IOException{
Socket connexion = new Socket(InetAddress.getLocalHost(), 33333);
BufferedReader input = new BufferedReader(
new InputStreamReader(connexion.getInputStream(), "8859_1"), 1024);
String res="";
while(input.readLine()!=null){
res += input.readLine()+"\n";
}
System.out.println(res);
}}
请给点建议?谢谢
【问题讨论】:
-
服务器不发送任何换行符。客户期望一个。所以它会阻塞,直到服务器发送一个。