Me ajudem por favor…
Estou fazendo um servidor para obter dados do sistema e envia-los para um cliente… ja fiz a GUI, blz… so que criei dois botões… ATIVA e DESATIVA… quando clico em ATIVA ele executa a trhead que contem o codigo do servidor… levanta o servidor na porta 6535 e ja tentei de tudo para matar a trhead e liberar o uso da porta 6535… se alguém poder me ajudar vou ficar grato… obrigado… Aqui vai uma parte do código…
class svr extends Thread{
public void run(){
String teste;
ServerSocket theServer;
Socket theConnection;
PrintStream p;
PrintStream d;
Properties props = System.getProperties();
String os_name = props.getProperty(“os.name”);
String os_versao = props.getProperty(“os.version”);
try {
theServer = new ServerSocket(6535);
try {
while (true) {
theConnection = theServer.accept();
p = new PrintStream(theConnection.getOutputStream());
p.println("-------------------");
p.println(“Sistema Operacional:\n” + os_name + “\n”);
p.println(“Versão:\n” + os_versao);
theConnection.close();
}}
catch (IOException e) {
theServer.close();
System.err.println(e);
}} catch (IOException e) {
lb2.setText(“Servidor ja ativado”);
}}}
…
ativa.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent actionEvent){
lb2.setText(“ATIVADO”);
new svr().start();
}});
desativa.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent actionEvent){
info.setText("");
lb2.setText("DESATIVADO");
new svr().stop();
}});