关于readLine有些不懂 请教
客户端以此方法发送字符串假设str为如下:
str="我是一个中国人!\n";
public boolean send(String str){
try {
socket = new Socket("localhost",8888);
out = new PrintWriter(socket.getOutputStream());
out.write(str);
out.flush();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
服务端
public void receive(ServerSocket serversocket){
System.out.println("=====begin receive====");
while(true){
try {
socket = serversocket.accept();
System.out.println("=====geted socket====");
new Thread(new Runnable(){
public void run() {
System.out.println("=====begin Thread====");
try {
StringBuffer Message = new StringBuffer();
read = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
String temp = read.readLine();
while(temp!=null){
Message.append(temp);
temp=read.readLine();
}
程序似乎会死在这,它总是认为没有到文件的末尾,怎么办啊
System.out.println("====Server Recevie======"+Message);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}