Estou iniciando Java RMI
E estou fazendo um programa para poder aprender como funciona fiz algumas coisas na faculdade tambem, mas estou com um problema quando vou executar meu servidor ele da a seguinte mensagem:
java.net connectException: connection refused to host: localhost
como resolvo este problema? alguem pode me ajudar?
não consigo fazer fucionar o projeto.
Obrigado a todos desde ja
Leandro Santos
Abaixo segue o código de todo o projeto:
================================================
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public class Servidor
{
public static void main(String[] args)
{
try
{
Aluno a1 = new Aluno();
Naming.rebind("//localhost/Aluno",a1);
System.out.println("Objeto aluno publicado...");
}
catch(Exception e)
{
System.out.println("Erro: " + e.getMessage());
}
}
}
================================================
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public interface IAluno extends Remote
{
public void setNome(String n) throws RemoteException;
public void setRgm(int r) throws RemoteException;
public String getNome() throws RemoteException;
public int getRgm() throws RemoteException;
public void setMed1(double m) throws RemoteException;
public void setMed2(double m) throws RemoteException;
public double getMed1() throws RemoteException;
public double getMed2() throws RemoteException;
public double getMedf() throws RemoteException;
public void calcularMedf() throws RemoteException;
public String situacao() throws RemoteException;
public void criar (int r, String n, double m1, double m2) throws RemoteException;
}
================================================
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
//classe Aluno é derivada de UnicastRemoteObject
//classe Aluno implementa IAluno
public class Aluno extends UnicastRemoteObject implements IAluno
{
//atributos
private int rgm;
private String nome;
private double med1;
private double med2;
private double medf;
//construtor
public Aluno() throws RemoteException
{}
//métodos de acesso
public void setNome(String n) throws RemoteException
{
nome = n;
}
public void setRgm(int r) throws RemoteException
{
rgm = r;
}
public String getNome() throws RemoteException
{
return nome;
}
public int getRgm() throws RemoteException
{
return rgm;
}
public void setMed1(double m) throws RemoteException
{
med1 = m;
}
public void setMed2(double m) throws RemoteException
{
med2 = m;
}
public double getMed1() throws RemoteException
{
return med1;
}
public double getMed2() throws RemoteException
{
return med2;
}
public double getMedf() throws RemoteException
{
return medf;
}
//calculo do valor de média final
public void calcularMedf() throws RemoteException
{
medf = (med1+med2)/2;
}
public String situacao() throws RemoteException
{
String sit = "";
if (medf >= 5)
{
sit = "Aprovado";
}
else
{
sit = "Reprovado";
}
return sit;
}
public void criar (int r, String n, double m1, double m2) throws RemoteException
{
rgm = r;
nome = n;
med1 = m1;
med2 = m2;
}
}
================================================
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public class Cliente
{
public static void main(String[] args)
{
try
{
IAluno a = (IAluno)Naming.lookup("aluno");
//a.setMed1(5);
//a.setMed2(7);
//a.setNome("Maria");
//a.setRgm(123);
a.criar(123,"Maria",5,9);
a.calcularMedf();
System.out.println("Nome: " + a.getNome());
System.out.println("RGM: " + a.getRgm());
System.out.println("Media1: " + a.getMed1());
System.out.println("Media2: " + a.getMed2());
System.out.println("Media final: " + a.getMedf());
System.out.println("Media2: " + a.situacao());
}
catch(Exception e)
{
System.out.println("Erro: " + e.getMessage());
}
}
}
================================================
