Yet another RMI Issue - java

Before you said that, yes, I know, there are a lot of threads which cover the same issue here on Stackoverflow, but any of those solved my problem. My problem is using the RMI interface (that is mandatory for my purposes) in two distinct computers, where one provides the RMI object (Server) and one asks for the Stub and obtains a Proxy. My code is the exact copy of the one provided by the Java 7 Reference Manual by Oracle and edited by Oracle Press:
IRmi.java
import java.rmi.*;
public interface IRmi extends Remote {
double add() throws RemoteException;
}
RmiImpl.java
import java.rmi.*;
import java.rmi.server.*;
public class RmiImpl extends UnicastRemoteObject implements IRmi {
public RmiImpl() throws RemoteException {}
public double add() { double d = 5.0; return d; }
}
Server.java
import java.net.*;
import java.rmi.*;
public class Server {
public static void main(String s[]) {
try {
RmiImpl ri = new RmiImpl();
Naming.rebind("Server",ri);
} catch (Exception e) {
System.err.println("Err");
}
}
}
Client.java
import java.rmi.*;
public class Client {
public static void main(String s[]) {
try {
IRmi itf = (IRmi)Naming.lookup("rmi://192.168.0.8/Server");
System.out.println(itf.add());
} catch (Exception e) {
e.printStackTrace();
}
}
}
After that, I compile with:
javac IRmi.java
javac RmiImpl.java
rmic RmiImpl
javac Client.java
javac Server.java
After that passage, I copy all the classes on both the client and the server, and then I run rmiregistry on the same folder where the classes were transfered. Assuming that in my local lan (192.168.0.0/255) there are two machines, where the client is 192.168.0.3 and the server 192.168.0.8 I run on those machine respectively java client and java Server, where the Client returns me the following error:
java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
java.net.ConnectException: Connessione rifiutata
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:129)
at RmiImpl_Stub.add(Unknown Source)
at Client.main(Client.java:8)
Caused by: java.net.ConnectException: Connessione rifiutata
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:147)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 5 more
For instance, In another test I've also tried to implement the server with this following code:
try {
RemImpl obj = new RemImpl(this.serv);
if (this.ob_list.size()>0) {
for (Observer ob: ob_list) {
obj.addObserver(ob);
}
}
this.myrec = (Rem) UnicastRemoteObject.exportObject(obj, 9999);
Registry registry = LocateRegistry.createRegistry(9999);
registry.rebind(this.serv, this.myrec);
//this.has_error = false;
System.out.println("Binded as "+this.serv);
} catch (RemoteException e) {
System.err.println("Remote exception catched: " + e.getMessage());
//this.has_error = true;
this.myrec = null;
}
and the client with the other following code:
try {
Registry registry = LocateRegistry.getRegistry(host);
this.myrec = (Rem) registry.lookup(service);
} catch (Exception e) {
e.printStackTrace();
}
and, in this case, the client returns me the following and different error:
java.rmi.NoSuchObjectException: no such object in table
ERROR
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy0.send(Unknown Source)
at rmi.lowlevel.NullSenderPolicy.send(NullSenderPolicy.java:81)
at message.policy.old.BroadcastSenderPolicy.single_send(BroadcastSenderPolicy.java:104)
at message.policy.old.AtomicBroadcastSender.fifo_send(AtomicBroadcastSender.java:54)
at message.policy.old.AtomicBroadcastNode.fifo_send(AtomicBroadcastNode.java:131)
at elements.testunit.TestPairBroadcastNodes.main(TestPairBroadcastNodes.java:20)
At this point I don't know which way to turn. Thanks in advance for any other kind suggestion.

The connection refusal seems to be a case of item A.1 in the RMI FAQ.
The NoSuchObjectInTable problem is because you're looking up the wrong Registry. You created it on port 9999 but you're looking up a different one. This can be cured by calling getRegistry(serverHost, 9999) in the client.
You should also make the Registry reference static in the server JVM.

Actually, the problem was lately solved by adding the -Djava.rmi.server.hostname=192.168.0.x argument on both client and server. Thanks for all the advices.

Related

How to use Java RMI with Dynamic Class Loading through HTTP Server?

i'm trying to implement a basic distributed application using the Java RMI framework.
Implementing it locally, I can do it, but when I want to manage dynamic class loading remotely, by loading the respective .class files of the classes on an HTTP Server in "Remote" (using virtual machines in the same local network), the Client fails to correctly download the .class for the stub:
Exception in thread "main" java.lang.NoClassDefFoundError: Example1 / RemoteAdd).
I have tried to run the Server in a Windows machine together with the RMI Registry, and in another virtual machine with Ubuntu (connected through a LAN) the Client (also in this machine there is also the HTTP Web Server with files. class).
But nothing, I get the exception:
Exception in thread "main" java.lang.NoClassDefFoundError: Example1 / RemoteAdd.
IP Window Machine (Server and RMI Registry) : 192.168.56.1
IP Ubuntu Machine (Client and HTTP Server) : 192.168.1.70
This is the Server class:
package Esempio1;
import java.rmi.Naming;
import java.security.Policy;
public class ServerAdd {
public ServerAdd() {
try {
System.setProperty("java.rmi.server.hostname","192.168.56.1");
System.setProperty("java.rmi.server.useCodebaseOnly","false");
System.setProperty("java.security.policy","policy.txt");
System.setProperty("java.rmi.server.codebase","http://192.168.1.70/Root/");
System.out.println(System.getProperty("java.rmi.server.codebase"));
System.out.println(System.getProperty("java.rmi.server.useCodebaseOnly"));
System.setSecurityManager(new SecurityManager());
RemoteAdd a = new ImpAdd();
Naming.rebind("add", a);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main (String[] args) {
new ServerAdd();
}
}
And this is Client:
package Esempio1;
import java.rmi.Naming;
public class ClientAdd {
public ClientAdd() {
try {
System.setProperty("java.security.policy","policy.txt");
System.setProperty("java.rmi.server.useCodebaseOnly","false");
System.out.println(System.getProperty("java.rmi.server.useCodebaseOnly"));
System.out.println(System.getProperty("java.security.policy"));
if(System.getSecurityManager()==null) {
System.setSecurityManager(new SecurityManager());
}
RemoteAdd a = (RemoteAdd) Naming.lookup("rmi://192.168.56.1:1099/add");
Integer x = new Integer(8);
Integer y = new Integer(2);
Integer c = a.sommaIng(x, y);
System.out.print(c.getClass()+" "+c);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main (String[] args) {
new ClientAdd();
}
}
I send the RMI Registry first like this:
start rmiregistry -J-Djava.rmi.server.useCodebaseOnly=false
Then I run the server on the same machine as the Registry, and it runs smoothly...
Finally I run the Client on the Ubuntu machine, and I get this error back:
Exception in thread "main" java.lang.NoClassDefFoundError: Esempio1/RemoteAdd
at Esempio1.ClientAdd.<init>(ClientAdd.java:23)
at Esempio1.ClientAdd.main(ClientAdd.java:37)
Caused by: java.lang.ClassNotFoundException: Esempio1.RemoteAdd
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Also this is the policy file used :
grant
{
permission java.security.AllPermission ;
};
The HTTP Server runs on Ubuntu through the Apache2 service and contains a Root folder with Esempio1 inside and all the .class files (192.168.1.70/Root/Esempio1)
Does anyone know where I'm wrong?

Trying to connect to RMI Registry but getting java.net.ConnectException: Connection refused: connect

I have two computers. On one of them, is running an RMI Registry - which was created from this code alone:
package main;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
public class TheRegistry{
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.createRegistry(2020);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
System.out.println("Registry Created");
Scanner input = new Scanner(System.in);
input.nextInt();
System.exit(0);
}
}
}
The other computer has a server that is trying to register an Object on this registry, however, it gets an exception. Here is the code for the server:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.*;
public class TextScramblerServer implements TextScramblerInterface
{
private static Remote obj;
// main method to export
#Override //Return input text as-is.
public String testInputText(String inputText) {
return "Your input text is: " + inputText;
}
#Override //Return the string reversed.
public String reverse(String inputText) {
String reversedInput = "";
for(int i=0; i<inputText.length();i++)
{
reversedInput=reversedInput+inputText.charAt((inputText.length()-1)-i);
}
return "Result: "+reversedInput;
}
#Override //Return the string scrambled.
public String scramble(String inputText) {
String scrambledInput="";
for(int i=0; i<inputText.length();i++)
{
if(i%2==0)
{
scrambledInput=scrambledInput+inputText.charAt(i);
}
else
{
scrambledInput=inputText.charAt(i)+scrambledInput;
}
}
return "Result: "+scrambledInput;
}
public void exportServer() throws Exception {
System.setSecurityManager(new RMISecurityManager());
obj = UnicastRemoteObject.exportObject(this, 2022);
Registry registry = LocateRegistry.getRegistry("132.205.94.50", 2020);
registry.bind("test", obj);
}
public static void main(String[] args) {
try {
(new TextScramblerServer()).exportServer();
System.out.println("Server is up and running");
}
catch(Exception e){
e.printStackTrace();
try {
UnicastRemoteObject.unexportObject(obj, true); //close port
} catch (NoSuchObjectException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
I keep getting the error:
java.rmi.ConnectException: Connection refused to host: 132.205.94.50; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at TextScramblerServer.exportServer(TextScramblerServer.java:57)
at TextScramblerServer.main(TextScramblerServer.java:62)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
... 7 more
java.rmi.NoSuchObjectException: object not exported
at sun.rmi.transport.ObjectTable.unexportObject(Unknown Source)
at java.rmi.server.UnicastRemoteObject.unexportObject(Unknown Source)
at TextScramblerServer.main(TextScramblerServer.java:68)
I can't figure out why this is happening. I think I've tried everything
I ran your code and it worked for me after configuring the security policy.
Your ConnectionRefused exception means that the underlying TCP connection cannot be established. It's network issue, not an RMI issue.
Try running both the server and registry on the same host, and use localhost as the hostname. If it works, the problem is likely a firewall issue between the two hosts.
You can do a simple test of a TCP connection to the specific port using telnet. If the port isn't listening, telnet will give you a similar connection refused message. If the port is listening, you'll get something like this on the terminal:
Connected to localhost.
Escape character is '^]'.
Control-C to get out of the session.
The specific telnet output may vary based on your OS, but they are all about the same.
If it is a firewall issue, you'll have to open up the ports. How to do that depends on OS, but it's easy to find.
Either your Registry has been garbage-collected, you got the IP address wrong, or it is a public IP address and you haven't configured port forwarding.
You need to store the Registry reference in a static object to overcome garbage collection, although what the point of that program is when rmiregistry.exe already exists escapes me completely.
You're barking up the wrong tree anyway. You can only bind to an RMI Registry that is running in the local host. There is therefore never any need to use a Registry hostname other than "localhost" when binding or unbinding.
The reason you got the NoSuchObjectException is that you are trying to unexport the stub, which is referred to by obj, which is the result of UnicastRemoteObject.exportObject(), which returns the stub. See the Javadoc. You need to save the result of new TextScramblerServer() and unexport that.

java.rmi.ConnectException: Connection refused to host: 192.168.0.55

I am quite a beginner with NetBeans and Java, so I'm pretty sure my questions are very basic but trying to find the solution for 2 weeks I am totally stuck
This is the problem:
I want to implement a RMI Server Client application
So first step was trying with NetBeans to have one work from the net
I used the oracle tutorial to have the first part implemented
http://docs.oracle.com/javase/tutorial/rmi/server.html
My problem is not that the client does not connect, but that the server can't even register in the port I give him. The IP in the error message is my private IP.
This is the error message I get:
Conectando a: 127.0.0.1 / 19400 / PlanificadorTalsa
ServidorPlanificadorStarter exception:
java.rmi.ConnectException: Connection refused to host: 192.168.0.55; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:342)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at Starter.ServidorPlanificadorStarter.main(ServidorPlanificadorStarter.java:52)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 5 more
I am running windows 8.1, and disabled firewall. I am also using a security file granting all permissions
this is my java code I execute from NetBeans:
import Conexion.DatosConexion;
import Servidor.*;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class ServidorPlanificadorStarter implements InterfazServidorPlanificador {
private static String ip;
private static String Servidor = "SERVIDORNUBE";
private static int puerto;
private static String nombreServidor;
public ServidorPlanificadorStarter(){
super();
}
public static void main(String[] args) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
DatosConexion datos = DatosConexion.getInstance();
ip = datos.getServiceIP(Servidor);
puerto = Integer.valueOf(datos.getServicePort(Servidor));
nombreServidor = datos.getServiceName(Servidor);
System.setProperty("java.rmi.server.hostname", ip);
System.out.println("Conectando a: " + ip + " / " + puerto + " / " + nombreServidor);
InterfazServidorPlanificador engine = new ServidorPlanificadorStarter();
InterfazServidorPlanificador stub =
(InterfazServidorPlanificador) UnicastRemoteObject.exportObject(engine, puerto);
Registry registry = LocateRegistry.getRegistry();
registry.rebind(nombreServidor, stub);
System.out.println("ServidorPlanificador bound");
} catch (Exception e) {
System.err.println("ServidorPlanificadorStarter exception:");
e.printStackTrace();
}
}
}
The interface is as follows (very basic, as I have done nothing with it)
public interface InterfazServidorPlanificador extends Remote {
//void addObserver(RemoteObserver o) throws RemoteException;
}
Did you start RMI registry as in tutorial?
http://docs.oracle.com/javase/tutorial/rmi/running.html

Socket programming - Client (linux), server (Windows)

I'm trying to create simple socket application using sockets to send stream from linux (64x ArchLinux) to server (Windows XP).
Code I'm using I found on the internet, just to check if it is working. What is interesting the code works perfectly if I'm using Windows XP (server) and Win 8 (client), but when client is on ArchLinux it does not work. Is there some special way to connect Windows-Linux ?
Server.java
import java.lang.*;
import java.io.*;
import java.net.*;
class Server_pzm {
public static void main(String args[]) {
String data = "Toobie ornaught toobie";
try {
ServerSocket srvr = new ServerSocket(1234);
Socket skt = srvr.accept();
System.out.print("Server has connected!\n");
PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
System.out.print("Sending string: '" + data + "'\n");
out.print(data);
out.close();
skt.close();
srvr.close();
}
catch(Exception e) {
System.out.print("Whoops! It didn't work!\n");
}
}
}
Client.java
import java.lang.*;
import java.io.*;
import java.net.*;
class Client {
public static void main(String args[]) {
try {
Socket skt = new Socket("192.168.224.78", 1234);
BufferedReader in = new BufferedReader(new
InputStreamReader(skt.getInputStream()));
System.out.print("Received string: '");
// while (!in.ready()) {} line removed
System.out.println(in.readLine());
System.out.print("'\n");
in.close();
}
/* lines removed catch(Exception e) {
System.out.print("Whoops! It didn't work!\n");
} */
// added exception handling
catch(UnknownHostException e) {
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
}
}
EDIT
Sorry, I did not specify what I meant by not working. I meant I got an exception which later prints System.out.print("Whoops! It didn't work!\n"); as in the catch blok. Win 8 and Arch Linux are installed on the same laptop, while the code is on my dropbox folder in both systems (so the code is the same) - I will post the actual exception, after I get back to my laptop
EDIT 2:
I updated code and this is exception I got:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
java.net.ConnectException: Connection refused
This has two possible meanings.
There is nothing listening at the address:port you tried to connect to.
There is a firewall rule in the way.
More likely 1. Firewalls usually just drop the packets, which causes a connection timeout rather than a refusal.
Are you sure you can establish connection between those systems? I have compiled and run your code on Windows 7 and Linux Mint on Virtualbox and it works correctly.
What do you mean "It doesn't work"? Does it throw any exception? If you just don't have any output, try to run it again and wait about 30 seconds.
For me it's just a network problem. So you should also try to ping your windows machine from linux and then try to telnet to server.
Edit:
So we know it is a network problem. First try to ping ip server from Linux system.
ping 192.168.224.78
If it didn't work, you should check if both machines are in the same subnet 192.168.224.0 assuming the mask is 255.255.255.0. You need just to type ifconfig in console.
In next step you should try to disable windows firewall. Here is an instruction how to do that.

RMI cannot connect to remote server

I've been plying with RMI recently and while I managed to make it work on locahost I've been having all sorts of problem when trying to use a remote server. Here's the basic code I'm trying to run:
Server:
public class RmiServer extends UnicastRemoteObject implements RmiServerIntf {
public static final String MESSAGE = "Hello world";
public RmiServer() throws RemoteException {
}
public String getMessage() {
return MESSAGE;
}
public static void main(String args[]) {
System.out.println("RMI server started");
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
System.out.println("Security manager installed.");
} else {
System.out.println("Security manager already exists.");
}
try {
LocateRegistry.createRegistry(1099);
System.out.println("java RMI registry created.");
} catch (RemoteException e) {
e.printStackTrace();
}
try {
RmiServer obj = new RmiServer();
Naming.rebind("rmi://localhost/RmiServer", obj);
System.out.println("PeerServer bound in registry");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Remote class interface:
public interface RmiServerIntf extends Remote {
public String getMessage() throws RemoteException;
}
Client:
public class RmiClient {
RmiServerIntf obj = null;
public String getMessage() {
try {
obj = (RmiServerIntf)Naming.lookup("rmi://54.229.66.xxx/RmiServer");
return obj.getMessage();
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
public static void main(String args[]) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
RmiClient cli = new RmiClient();
System.out.println(cli.getMessage());
}
}
rmi.policy file:
grant {
permission java.security.AllPermission;
};
I compiled the classes and created a stub for the server. Then I placed client, stub, interface and policy on my machine and server, stub, interface and policy on the remote machine. The remote server being a Linux machine I made all the files executable. I also added a rule on the local firewall allowing port 1099, and opened all ports on the remote machine
After this I navigated to the server's directory on the remote machine and inserted the following command:
java -Djava.security.policy=rmi.policy RmiServer
This didn't give me problems so I went back to the local machine and entered
java -Djava.security.policy=rmi.policy RmiClient
I wait, and wait and I get the error message:
Connection refused to host: 172.31.xx.xx; nested exception is: java.net.ConnectException: Connection timed out: connect
I've been fighting with these connection errors all day yesterday and this is as far as I got. I'm sure there's only one very small thing I'm still doing wrong but I just can't find what it is.
This may not solve your problem, but I've had similar issues with JPPF (via Java RMI) on Linux. The solution was to ensure that the ephemeral port range on the Client-side machine covered only ports that were allowable by the Client-side's local firewall. E.g., if your firewall allows ports 48000 to 64000 to be connected to by an external machine, ensure that your ephemeral port range also falls within 48000 to 64000. Give that a try and let us know what happens.
System.setProperty("java.rmi.server.hostname","10.0.3.73");
Please use the above statements in your RMIServer side code, and try and connect from remote client again. It worked for me

Categories