How can I stop a server socket which is listening client. My code look like below
private ServerSocket serverSocket;
class ServerThread implements Runnable {
private BufferedReader input;
public void run() {
Socket socket = null;
try {
serverSocket = new ServerSocket(SERVE_LISTEN_RPORT);
} catch (IOException e) {
e.printStackTrace();
}
while (!Thread.currentThread().isInterrupted()) {
try {
socket = serverSocket.accept();
try {
this.input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}
try {
String read = input.readLine();
//Do something
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
try {
serverSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I need to stop this thread when I got a command from another thread. I already sow this question but no idea how to implement it.