[英]Java Networking Server, protocol and client
I have this multi server thread, so whenever the 'X' button is click on the top right hand corner, i want to display the message "closing the socket" on the server side. 我有这个多服务器线程,因此每当单击右上角的“ 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;
}
But it doesn't work, and i have to manually end the process for the server side. 但这不起作用,我必须手动结束服务器端的过程。 I assume that it got stuck at the while loop, but i couldn't figure out whats wrong with it.
我认为它被困在while循环中,但是我不知道它到底出了什么问题。
假设您无法诱使服务器向您发送Bye消息,则可以退出循环,就好像它已经向您发送了Bye消息,或者关闭另一个线程的套接字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.