BufferedReader 및 Buffered Writer를 통해 클라이언트/서버 소켓 연결을 시도하고 있지만 판독기가 읽히지 않은 경우 클라이언트가 올바르게 보내고 플러시되는 위치에 방금 정지되었습니다. 클라이언트가 서버에 아무것도 보내지 않는 것처럼 서버가 예외를 throw하지 않습니다. 클라이언트와 서버에 대해 동일한 사용하여 내 머리가 폭발 갈 것입니다Java 소켓 BufferedReader 읽기 읽기가 없습니다.
...
임 :
//inside of try catch
while(true){
while(!in.ready())// just to debug
System.out.println("READY: " + in.ready()); //just to debug
System.out.println("READY: OK"); //just to debug
msg = receive().toString(); //hangs here...
System.out.println("KEYIS: " + msg);
///some stuff to do ....
public StringBuilder receive() throws IOException {
StringBuilder str = new StringBuilder();
int tmp;
while(true){
tmp = in.read();
if(tmp == 0)
break;
else if(tmp == -1)
throw new IOException();
str.append((char)tmp);
}
return str;
}
클라이언트 코드 : 여기
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
서버의 코드입니다 : 여기에 걸려 있지 않다
//inside of try catch
send(KEY); //sended properly, no exception
while(true){
send(KEY); // sended properly, no exception
System.out.println("sent");
//System.out.println(receive().toString());
}
public void send(String str) throws IOException{
out.write(str + "\n"); //
//out.newLine(); //tried too, not helped
out.flush(); //push message to server
}
가 왜 당신을 ... \ 0 더 많은 데이터가 오는 것처럼, 그래서를 받게되며 방법은 기다리고 있었다 메시지의 끝을 결정하기 위해 추가하는 것을 잊었다 BufferedReader를 사용 하시겠습니까? 그것을 제거하려고 노력하면 도움이 될 것입니다. – vbezhenar