RMI+Eclipse

Status
Nicht offen für weitere Antworten.
C

Chrisi321

Gast
Kann mir jamand erklären, wie man RMI Server und Clients in Eclipse startet?
 
T

tuxedo

Gast
Wie normale Anwendungen auch. Extra Plugins braucht man nicht mehr.

Die RMI-Registry lässt sich seit einiger Zeit auch "programmatisch" starten.

- Alex
 
G

Guest

Gast
Code:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
...
Registry reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); // Port 1099
 
C

Chrisi321

Gast
Server:

import java.net.InetAddress;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class server implements serverinfo{

private final InetAddress a;

public static void main(String[] args) throws Exception
{
server s = new server();

serverinfo stub = (serverinfo)UnicastRemoteObject.exportObject(s,0);

Registry registry = LocateRegistry.getRegistry();

registry.bind("serverinfo", stub);
System.out.println("Server läuft.");
}

public server() throws Exception
{
a = InetAddress.getLocalHost();
}

public String getServerIp()
{
return a.getHostAddress();
}

public String getServerName()
{
return a.getHostName();
}
}

import java.rmi.*;

public interface serverinfo extends Remote
{
String getServerIp() throws RemoteException;
String getServerName() throws RemoteException;
}

Das sind die Fehlermeldungen:

Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 127.0.0.1; 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.list(Unknown Source)
at client.main(client.java:12)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(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)
... 6 more
 

tfa

Top Contributor
Die Exception wird offensichtlich vom Client geschmissen.
Wenn du den Client-Quelltext postest, bitte benutze Code-Tags!
 

Chrisi3210

Aktives Mitglied
Code:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class client {

   public static void main(String[] args) throws Exception
   {
      Registry registry = LocateRegistry.getRegistry("127.0.0.1");
      
      String[] services = registry.list();
      
      for(int i=0; i<services.length; i++)
         System.out.println("Service gefunden: " + services[i]);
      
      serverinfo stub = (serverinfo)registry.lookup("ServerInfo");
      System.out.println("Server IP: " + stub.getServerIp());
      System.out.println("Server Name: " + stub.getServerName());
   }
   
}

Beim Starten des Clients kommt die Selbe Fehlermeldung.
 
T

tuxedo

Gast
Wenn der Server nicht funzt ist es vollkommen klar, dass der Client sich nicht verbinden kann. Lass mal den Servercode sehen. Vor allem die stelle wo

Code:
Registry reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); // Port 1099

aufgerufen wird.

- Alex
 
Status
Nicht offen für weitere Antworten.

Oben