Encerrar Conexão com o Cliente

0 respostas
Matrirxp

Ola galera, Estou com um problema para encerrar a conexão com o cliente do servidor, quando o comando para encerrar a conexão e recebido ele pula o comando Client.close().

Script:

/*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package a.i.d.s.server;

    import static a.i.d.s.server.AIDSServer.*;
    import static a.i.d.s.server.Controle_GUI.*;
    import static a.i.d.s.server.Information_Host.HostsIp;
    import java.io.IOException;
    import java.net.Socket;
    import java.util.logging.Level;
    import java.util.logging.Logger;

    /**
     *
     * @author Matheus
     */
    public class Connect_Client extends Thread{
        
        static String ConnectIp;
        public static Socket Client;
         public static boolean Connect_Stats;
         public static boolean close;
         public static boolean Connect_All;
         
         static int TIME_OUT = 120;
         int Block;
         
         public static boolean SendCommands;
        
       public void run(){
           
              while (true) {  
                  
                  
                  
                 if(Connect_Op == 0){
                    ConnectIp = null; 
                    
                    Connect_All = false;
                    
                 }
                
                 
                 
                if(Connect_Op == 1){
                    
                    Connect_All = false;
                    
                    
                    
                    ConnectIp = Box1.getSelectedItem().toString();      
                    
                     try {
                         if(Block == 0){
                             
                            
                             
                             if(Connect_Stats == false){
                                  System.out.println("Connecting...");
                         Client = new Socket(ConnectIp,Port_Client);
                             }
                         Connect_Stats = Client.isConnected();
                         
        TIME_OUT_TIMER timer = new TIME_OUT_TIMER();
        Thread threadTime = new Thread((Runnable) timer);
        threadTime.start();
        
        Block += 1; 
                         }
                         
                         label9.setText("TIME_OUT: "+TIME_OUT);
                         
                         
                         if(TIME_OUT <= 0){
                             label9.setText("");
                             close = true;
                         }
                         
                         
                         
                          if(SendCommands == true){
                              
                          new Commands();
                          }
                          
                          
                       if(close == true){
                            try {
                                
                      **> Client.close();**
                      
                           System.out.println("Client Stats: "+Client.isConnected());
                           System.out.println("Client IP: "+ Client.getInetAddress().getHostAddress());
                       
                                 Thread.sleep(100);
                             
                       label9.setText("");
                       
                                 Thread.sleep(100);
                        
                      label4.setText("Connection Closed");
                      label4.setForeground(java.awt.Color.BLUE);
                     Connect_Stats = false;
                                 Thread.sleep(100);
                            
                      Connect_Op = 0;
                      TIME_OUT = 120;
                      SendCommands = false;
                      Block = 0;
                       
                                 Thread.sleep(200);
                            
                      close = false;
                      
                      } catch (InterruptedException ex) {
                                 Logger.getLogger(Connect_Client.class.getName()).log(Level.SEVERE, null, ex);
                             }
                           }
                         
                     } catch (IOException ex) {
                         Logger.getLogger(Connect_Client.class.getName()).log(Level.SEVERE, null, ex);
                     }
                    
                    
                    
       
                }
                
                //CONNECT ALL
                if(Connect_Op == 2){
                    
                    Connect_All = true;
                    
                 for(int i = 0; i < HostsIp.size();i++){
                    
                     
                     try {
                         
                         if(Block == 0){
                             
                             if(Connect_Stats == false){
                         Client = new Socket(HostsIp.get(i),Port_Client);
                             }
                         
                         Connect_Stats = Client.isConnected();
                         
        TIME_OUT_TIMER timer = new TIME_OUT_TIMER();
        Thread threadTime = new Thread((Runnable) timer);
        threadTime.start();
                         
        Block += 1;
                         }
                         
                         label9.setText("TIME_OUT: "+TIME_OUT);
                         
                         if(TIME_OUT <= 0){
                             label9.setText("");
                             close = true;
                         }
                         
                     if(SendCommands == true){
                         System.out.println("Deu Merda");
                      new Commands();
                     }
                         
                      int SizeEn = 0;
                      SizeEn += 1;
                      
                      int EnSize = SizeEn - HostsIp.size();
                      
                      label4.setText("Sending: " + EnSize + " of " + HostsIp.size());
                      
                        if(close == true){
                            try {
                      Client.close();
                       
                                 Thread.sleep(100);
                             
                       label9.setText("");
                       
                                 Thread.sleep(100);
                        
                      label4.setText("Connection Closed");
                      label4.setForeground(java.awt.Color.BLUE);
                     Connect_Stats = false;
                                 Thread.sleep(100);
                            
                      Connect_Op = 0;
                      TIME_OUT = 120;
                      SendCommands = false;
                      Block = 0;
                       
                                 Thread.sleep(200);
                            
                      close = false;
                      
                      } catch (InterruptedException ex) {
                                 Logger.getLogger(Connect_Client.class.getName()).log(Level.SEVERE, null, ex);
                             }
                           }
                         
                         
                     } catch (IOException ex) {
                         Logger.getLogger(Connect_Client.class.getName()).log(Level.SEVERE, null, ex);
                     }
                      
                 
                      
                           
                  }
                  
                }
        
            }//While
             
         }
        
        
        
        
    }//Class
Criado 28 de agosto de 2017
Respostas 0
Participantes 1