elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


  Mostrar Temas
Páginas: [1]
1  Programación / Java / Ayuda ServidorAVL en: 27 Marzo 2014, 14:18 pm
Estimados,
Junto con saludar le comento mi problema, me encuentro implementando un sistema de monitoreo gps via web. La parte web lo tengo todo listo pero la aplicación que es el corazón de mi sistema es un serverSocket , el cual se encarga de la comunicacion con los GPS, leer los datos, validarlos e insertarlos en la bbdd. a simple vista la rutina es muy sencilla y la tengo implementada, pero resulta que al cabo de un o dos dias se cae el serverSocket por lo que yo de tengo el proceso y los inicio de nuevo pero no es lo optimo no he podido encostrar el problema por lo que acudo a los mas experimentados del foro para solicitar su ayuda.
adjunto los codigos.
Código
  1. public void run(){
  2.  
  3. while (conectado){
  4.            procesarEntrada();
  5.            try
  6.            {
  7.                //System.out.println("\n hebra durmiendo");
  8.                Thread.sleep(1000);
  9.            }
  10.    catch (InterruptedException ex)
  11.            {
  12.               escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error : en la hebra InterruptedException =" + ex.getMessage()+"\n");                
  13.            }
  14.            catch(Exception ex){
  15.               escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error : en la hebra Exception =" + ex.getMessage()+"\n");    
  16.            }
  17.        }//Fin while conectado  
  18.  
  19.        // Cierro el imput stream y el socket
  20.        try {
  21.            in.close();
  22.    out.close();
  23.            try
  24.            {
  25.               conectar.close();
  26.            }
  27.            catch (SQLException ex)
  28.            {
  29.                 escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error:  Al cerrar la conexion con la bbdd "+ex.getSQLState()+"\n");
  30.            }        
  31.   System.out.println(this.getName()+" "+obtenerfecha()+"-" + p.getDeviceId() + "- Desconectado.\n");
  32.           escribirA.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-" + p.getDeviceId() + "- Desconectado.\n");
  33.  
  34.        } catch (IOException ex) {
  35.           //ig.setRecibido("Error al cerrar la conexion con el dispositivo "+p.getDeviceId()+" . "+ex.getMessage()+"\n");
  36.           escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: E/S al cerrar la conexion con el dispositivo "+p.getDeviceId()+" : "+ex.getMessage()+"\n");
  37.        }
  38.        catch (Exception ex){
  39.            escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: Exception al cerrar la conexion con el dispositivo "+p.getDeviceId()+" : "+ex.getMessage()+"\n");
  40.        }
  41.  
  42.  
  43.    } //fin run  
  44.  
  45.    public void leerSocket(){
  46.        try{
  47.            // Lee un mensaje enviado por el cliente
  48.            this.mensajeRecibido = in.readLine();
  49.            //envia el id al dispositivo
  50.            this.out.flush();
  51.        }catch (IOException ex){
  52.            this.detener();
  53.            escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: E/S del dispositivo :" + ex.getMessage()+"\n");
  54.            try {
  55.                in.close();
  56.                out.close();
  57.            } catch (IOException ex1) {
  58.                escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: E/S al cerrar el stream de entrada :" + ex1.getMessage()+"\n");
  59.            }catch(Exception ex2){
  60.                escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: Exception al cerrar el stream de entrada :" + ex2.getMessage()+"\n");
  61.            }
  62.        }catch (Exception ex){
  63.            this.detener();
  64.            escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: Exception del dispositivo :" + ex.getMessage()+"\n");
  65.            try {
  66.                in.close();
  67.                out.close();
  68.            } catch (IOException ex2) {
  69.                escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: E/S al cerrar el stream de entrada :" + ex2.getMessage()+"\n");
  70.            }catch(Exception ex2){
  71.                escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: Exception al cerrar el stream de entrada :" + ex2.getMessage()+"\n");
  72.            }
  73.        }      
  74.    }
  75.  
  76.    public void protocolizarMensaje(){
  77.        try{
  78.            if(this.mensajeRecibido != null)
  79.            {
  80.                this.p = this.protocolo.decode(this.mensajeRecibido);
  81.                this.out.writeUTF(p.getDeviceId());
  82.            }
  83.        }catch (Exception ex){
  84.            escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: Exception al protocolizar el mensaje  :" + ex.getMessage()+"\n");
  85.        }
  86.    }
  87.  
  88.    public void insertarMensaje(){
  89.        if(this.mensajeRecibido != null){
  90.           if(this.mensajeRecibido.contains(">REV")){
  91.               if(this.p.getLatitude().equals(0.0)||this.p.getLongitude().equals(0.0)){
  92.                   //ig.setRecibido("Conectando con el satelite\n");
  93.                   escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-"+p.getDeviceId()+"-Conectando con el satelite\n");
  94.               }
  95.               else{
  96.                   //System.out.println(p.getTime()+"\n"+cont);
  97.                   this.db.insertarPosicion(conectar,p);
  98.                   //guardoId=p.getDeviceId();
  99.                   System.out.println(this.getName()+" "+this.p.getDeviceId()+" "+this.p.getTime()+" "+this.p.getDate()+"-Posicion Actualizada\n");
  100.                   escribirA.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-"+this.p.getDeviceId()+" - "+this.p.getTime()+" - Posicion Actualizada\n");
  101.               }
  102.           }
  103.        }
  104.        this.mensajeRecibido="";
  105.    }
  106.  
  107.     public synchronized void procesarEntrada(){
  108.        //try {
  109.            //this.semaforo.acquire();
  110.            leerSocket();
  111.            protocolizarMensaje();
  112.            insertarMensaje();
  113.            //this.semaforo.release();
  114.        //} catch (InterruptedException ex) {
  115.           // escribirE.EscribirArchivo(this.getName()+" "+obtenerfecha()+"-Error: InterruptedException al interrumpir la hebra :" + ex.getMessage()+"\n"); }
  116.     }
  117.  
  118.  
  119.  
agradezco cualquier tips para sacar el proyecto adelante muchas gracias.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines