1
로그인 통신을 위해 클라이언트를 수행하고 있습니다.Java SocketException 브로큰 파이프
나는 java.net.SocketException : Server end에서 파이프를 깨뜨 렸습니다. 그리고 난 문제를 한 줄로 클라이언트 쪽 좁혔습니다. 이 행의 위치를 이동하면 코드가 작동합니다. plese는 다음 코드를 참조하십시오.
클라이언트 종료 :
Socket socket = new Socket(Const.destIp, 12101);
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
out.writeObject(this.message);
out.close();//Line that cause problem
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
ServerToClientLogin msg = (ServerToClientLogin) in.readObject();
//out.close();//move it to here, problem solved
in.close();
socket.close();
서버 쪽 끝의 readObject와 writeObject에 통화를 차단하고 있기 때문에
while (true) {
socket = _serverSocket.accept();
in = new ObjectInputStream(socket.getInputStream());
msg = (ClientToServerLogin) in.readObject();
ServerToClientLogin msgToSend = null;
out = new ObjectOutputStream(socket.getOutputStream());
msgToSend = handleLoginRequest(msg);
if(msgToSend != null) out.writeObject(msgToSend);
try { in.close(); } catch (IOException e) {e.printStackTrace();}
try { out.close();} catch (IOException e) {e.printStackTrace(); }
try { socket.close();} catch (IOException e) {e.printStackTrace();}
}
, 내가 이전 등의 문제를 구분 왜 가까운 아무 생각이 없습니다.
out이 ObjectOutputStream 유형이고, out.close()를 호출하면 소켓이 닫힙니 까? – SDEZero
이 출력 스트림을 닫고이 스트림과 연결된 모든 시스템 리소스 (API – PbxMan
@PbxMan)를 해제합니다. 응답에 추가 한 내용을 추가하면 명확 해집니다. – acdcjunior