Java - Urgente RMI

 
Vista:

Urgente RMI

Publicado por PXC (4 intervenciones) el 13/05/2009 18:49:07
Hola, somos un grupo de estudiantes que debemos entregar un proyecto y tenemos problemas con el RMI de java. A ver si alguien puede resolvernoslo.

Tenemos 3 classes el Hello, que es la interfaz, Server i Cliente, podeis encontrar-las las 3 mas abajo.

El caso es el siguiente:

Tenemos un servidor con un Linux instalado con la aplicacion Server i Hello. ejecutamos rmiregistry y java -classpath bin -Djava.rmi.server.codebase=file:bin/ example.hello.Server

Hasta aqui no hay problema, nos sale el mensaje de Server ready

El problema lo tenemos en la ejecución del cliente.

java -classpath bin -Djava.rmi.server.hostname=wwweather.no-ip.org example.hello.Client

Si os fijais en el codigo hay una instrucción para que nos liste todos los objetos del rmiregistry y nos aparece el Hello.

Si embargo quando realiza la llamada a la instruccion
respuesta=stub.sayHello();
nos da el siguiente error.
Client Exception: java.rmi.ConnectException: Connection refused to host:127.0.0.1; nested exception is:
java.net.ConnectionException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)


y continua.

aparece por alli en medio un
at $Proxy0.sayHello(Unknown Source)
at example.hello.Client.main(Client.java:56)

-----------------------------------
package example.hello;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
-----------------------------------

package example.hello;

import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class Server implements Hello {

public Server() {}

public String sayHello() {
return "Hello, world!";
}

public static void main(String args[]) {
System.setProperty("java.security.policy","general.policy");
try {
Server obj = new Server();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);

// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("Hello", stub);

System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
-------------------------------------------------------------------------
package example.hello;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Client {

private Client() {}

public static void main(String[] args) {
System.setProperty("java.security.policy","general.policy");
System.setProperty("java.rmi.server.hostname","wwweather.no-ip.org");

String host = "wwweather.no-ip.org";
try {
Registry registry = LocateRegistry.getRegistry(host);
System.out.println(registry.list()[0]);
Hello stub = (Hello) registry.lookup("Hello");
String response = stub.sayHello();
System.out.println("response: " + response);
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Urgente RMI

Publicado por wendy callisaya (1 intervención) el 27/10/2009 20:38:21
quiro hacer un foro ocupando rmi
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar