0
나는이 다중 서버 스레드를 가지고 있으므로 'X'버튼을 클릭 할 때마다 오른쪽 상단 모서리에서 "소켓 닫기"메시지를 서버 측에 표시하려고합니다.자바 네트워킹 서버, 프로토콜 및 클라이언트
public void run
{
try
{
// .....
String inputLine, outputLine;
Protocol p = new Protocol();
outputLine = p.processInput(null, p);
out.println(outputLine);
while ((inputLine = in.readLine()) != null) {
outputLine = p.processInput(inputLine,p);
out.println(outputLine);
if (outputLine.equals("Bye"))
{
System.out.print("Closing socket.");
break;
}
}
out.close();
in.close();
socket.close();
catch (IOException e)
{
// .....
}
}
public String processInput(String theInput, Protocol p)
{
theOutput = null;
frame = new JFrame ("Find The Word!");
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
theOutput = "Bye";
}
});
frame.add(p);
frame.pack();
frame.setVisible(true);
return theOutput;
}
하지만 작동하지 않으며 서버 측 프로세스를 수동으로 종료해야합니다. 나는 그것이 while 회 돌이에서 멈추었다고 추측하지만 그것으로 무엇이 잘못되었는지를 알 수 없었다.
버튼의 청취자는 무엇입니까? –
창 단추에 수신기를 추가 할 수 없습니다. 그것은 WindowAdapter를 사용하여 올바르게 처리됩니다. – desperateCoder
서버 안의 while 루프를 깨뜨리기 위해 "Bye"가 리턴 될 것입니다. – june