나는 내 것과 비슷한 문제를 봤지만이 문제를 해결할 수 없었습니다. 릴레이 채팅을하려고합니다. 나는 플러싱을 다했다. 심지어 autoflush (println 사용)도 시도했습니다. 그러나 서버로 보낸 첫 번째 메시지가 끝나면 이후의 메시지는 더 이상 전송되지 않습니다. 나는 인쇄 작가를 닫지 않을 것이다. 소켓을 확인했는데 그래, 아직 연결되어있어 보낼 메시지를 인쇄했는데 아무것도 잘못된 것 같아. 도움말은 대단히 감사하겠습니다. 여기 PrintWriter가 첫 번째 메시지 만 보냄
클라이언트 코드의 일부이다 : 이public void initializeConnection(){
try {
host = InetAddress.getLocalHost();
clientSocket = new Socket(host.getHostAddress(), port);
outToServer = new PrintWriter(clientSocket.getOutputStream(),true);
String message = outMsgArea.getText()+"Hello";
outToServer.println(message);
System.out.println(clientSocket.isConnected());
}
catch(IOException ioEx) {
ioEx.printStackTrace();
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==quit){
try {
outToServer.close();
clientSocket.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
else if(e.getSource()==button){
if(outMsgArea.getText()!=null || !outMsgArea.getText().equals("")){
/*try {
outToServer = new PrintWriter(clientSocket.getOutputStream(), true);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}*/
String message = outMsgArea.getText()+"Hello";
System.out.println(clientSocket.isConnected());
outToServer.println(message);
outToServer.flush();
//outToServer.println(message);
outMsgArea.setText("");
}
}
}
서버 :
while(true) {
try {
Socket connectionSocket = servSocket.accept();
Scanner inFromClient = new Scanner(connectionSocket.getInputStream());
String clientSentence = inFromClient.nextLine();
System.out.println(clientSentence);
}
catch(IOException ioEx) {
ioEx.printStackTrace();
}
}
}
코드를 공유 할 수 있습니까? –
몇 가지 코드를 게시하십시오. –
서버를 작성 했습니까? 입력을 처리하는 코드를 게시 할 수 있습니까? – Kevin