ConnectException on RMI method invocation on brick

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

ConnectException on RMI method invocation on brick

Postby mpscholz » Sun Jun 22, 2014 10:02 am

Hi,
I'm trying to implement a Remote Method Invocation application presently where a PC app calls a method of a RemoteObject in the EV3 brick's registry.
Sadly, even a very simple test app that connects on port 1098 fails for me.

On the brick, there the "server" app

Code: Select all
   public static void main(String[] args) {
      try {
         IRemoteObject stub = (IRemoteObject) UnicastRemoteObject
               .exportObject(new RemoteObject(), 0);
         Registry registry = LocateRegistry.createRegistry(1098);
         registry.rebind(IRemoteObject.BIND_NAME, stub);
      } catch (Exception e) {
         System.err.println("RemoteException: " + e);
      }
   }


while on the PC, this "client" app tries to call the execute() method of the IRemoteObject:

Code: Select all
       public static void main(final String[] args) {
      try {
         final Registry registry = LocateRegistry.getRegistry("10.0.1.1",
               1098);
         final IRemoteObject remoteObject = (IRemoteObject) registry
               .lookup(IRemoteObject.BIND_NAME);
                  remoteObject.execute();
      } catch (final Exception e) {
         System.err.println("Exception occurred: " + e);
         e.printStackTrace();
      }
   }

The IRemoteObject interface and its implementation are very simple:

Code: Select all
public interface IRemoteObject extends Remote {

   String BIND_NAME = "RemoteObject";

   void execute() throws RemoteException;

}


and

Code: Select all
public class RemoteObject implements IRemoteObject {

   @Override
   public void execute() {
      System.out.println("RemoteObject.execute()");
   }

}


The server app starts fine on the brick , but when I run the client app on the PC afterwards, the client throws a ConnectException when trying to execute the remote method on the proxy (stack trace see below).

Tried it on three different client machines, two of them running Windows 7, one Linux (Ubuntu 14), as well as with USB, BT and WiFi connection, with two different EV3 bricks - always the same result. :(
Strangely enough, the EV3 Control Center runs like a charm in any of these setups, and I can also connect with the client against the server app when it does not run on the brick but locally on the PC.

Firewall is deactivated on the client machine, so the port should be open.
I use leJOS EV3 0.8.1-beta, Java 7 and start both apps with the "Run as ..." feature in Eclipse.

So what am I doing wrong?

Stack Trace:
Exception occurred: java.rmi.ConnectException: Connection refused to host: ; nested exception is:
java.net.ConnectException: Connection refused: connect
java.rmi.ConnectException: Connection refused to host: ; 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.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.mp.lejos.ev3.rmitest.pc.RemoteClient.main(RemoteClient.java:16)
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)
... 8 more
leJOS Developer
mpscholz
New User
 
Posts: 20
Joined: Fri Jan 18, 2008 1:37 pm
Location: Germany

Re: ConnectException on RMI method invocation on brick

Postby gloomyandy » Sun Jun 22, 2014 6:01 pm

No real idea on this. Lawrie is our RMI expert, one possible problem though, could it be that the leJOS menu (which obviously has its own RMI interface), is interfering with your program? You could try logging in via ssh and killing the menu and then running your program by hand... As I say I am no expert on this so the above may not help at all...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4119
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: ConnectException on RMI method invocation on brick

Postby lawrie » Tue Jun 24, 2014 8:22 pm

Hi Matthias,

To make the menu work I had to do:

System.setProperty("java.rmi.server.hostname", <ip-address>);

Without that the server was sending to the client my external IP address rather than the Wifi LAN Ip address of the server. The client would then fail to connect.

I don't know if that could be your problem. I am not an expert on this - I just got something to work and stuck with it.

Lawrie
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Re: ConnectException on RMI method invocation on brick

Postby mpscholz » Fri Jun 27, 2014 7:16 am

Thanks Lawrie,

Setting the system property as proposed did the job for me finally! :)

Best,
MP
leJOS Developer
mpscholz
New User
 
Posts: 20
Joined: Fri Jan 18, 2008 1:37 pm
Location: Germany

Re: ConnectException on RMI method invocation on brick

Postby skoehler » Fri Jun 27, 2014 9:29 am

So after all these years, RMI still can't deal with a multi-homed host. That is pretty embarrassing. Note that setting the system property is likely to make it possible to have, simultaneously, a connection to the EV3 and a PC in the LAN. A bug report can be found here:
http://bugs.java.com/bugdatabase/view_b ... id=4880793

I'm not sure whether Sun/Oracle is thinking in the right direction. I skimmed the bug report, and the proposed solution seems to be to bind the registry to a certain address. Which of course begs the question: which one? (They basically propose to shift the problem from the system library to user code). A truly automatic way of dealing with the problem should be to first establish a TCP connection to the remote registry, and then to look at the local address of that TCP socket. For a multihomed host, the OS will automatically bind the TCP socket to the right interface that, according to the routing table, is capable of reaching the remote host. That address is to be sent to the remote registry.
skoehler
leJOS Team Member
 
Posts: 1431
Joined: Thu Oct 30, 2008 4:54 pm


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff