버퍼에서 문자열을 읽고 서버에 쓰고 있습니다. 내가 가지고있는 문제는 소켓을 열어두고 루프를 쓸 때 문자열이 서버에 수신되지 않는다는 것입니다. 나는이 사용하는 경우 :writeBytes를 사용하는 Java 클라이언트 소켓
try {
Socket send = new Socket("localhost", 1490);
DataOutputStream out = new DataOutputStream(send.getOutputStream());
String message = null;
while ((message = buffer.get()) != null){
out.writeBytes(message);
}
out.close();
send.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
서버가 문자열을받지 않습니다,하지만 난이 작업을 수행 할 때 제대로 작동 : 분명히
try {
String message = null;
while ((message = buffer.get()) != null){
Socket send = new Socket("localhost", 1490);
DataOutputStream out = new DataOutputStream(send.getOutputStream());
out.writeBytes(message);
out.close();
send.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
나는 개방과 폐쇄를 유지하지 않으을 소켓. 문제가 무엇입니까?
예, 플러시를 시도했지만 여전히 동일한 문제가 있습니다. 버퍼에는 항상 문자열이 있으므로 소켓이 실제로 닫히지 않는다고 생각합니다. 그런데도 내 메시지가 아직받지 못하는 이유는 무엇입니까? – user1190650