RMI - servidor que processa o objeto remoto não finalizar a execução

1 resposta
A

Oi galera, como fazer com q o servidor q processa a solicitação de um stub não finalize a execução?
Valeu…

1 Resposta

Slipguedes
a2sjunior:
Oi galera, como fazer com q o servidor q processa a solicitação de um stub não finalize a execução? Valeu...
Vc precisa fazer com q ele execute de novo e fique aguardando a conexão. De uma olhada no código.
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.AlreadyBoundException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.Naming;
import java.net.MalformedURLException;


public class ServidorImpl implements Servidor{

    public ServidorImpl(){
    	inicia();
    }
    
    public void inicia(){
    	try{
    		//exporta o objeto remoto
    		Servidor stub = (Servidor)UnicastRemoteObject.exportObject(this,0);
    		
    		//liga o stub do objeto remoto no registro, e inicia o RMIRegistry na porta 1000
    		Registry registry = LocateRegistry.createRegistry(1000);
    		
    		//dá um nome pra ele no registro
    		registry.bind("Servidor", stub);
    		
    		System.out.println("Servidor iniciado...");
    	}catch(RemoteException  re){
    		System.out.println(re.getMessage());
    	}catch(AlreadyBoundException abe){
    		System.out.println(abe.getMessage());
    	}catch(IOException ioe){
    		System.out.println(ioe.getMessage());
    	}
    }
        
    public static void main(String[] arg){
   
    	 try{
  
    	 ServidorImpl objt = new ServidorImpl();

         Naming.rebind("rmi://127.0.0.1/Servidor", objt);
         System.out.println("Servidor Rodando...");
    	 }catch(MalformedURLException murl) {
                       System.out.println("a URL nao foi encontrada.");
                       murl.getMessage();
    	 }catch(RemoteException re){
    	 	
    	 }
    }
}
Com esse código o servidor vai ficar aguardando a conexão do cliente. Valeu. Qualquer dúvida posta ai.
Criado 28 de maio de 2008
Ultima resposta 29 de mai. de 2008
Respostas 1
Participantes 2