Hallo,
versuche grade eine gestellte Aufgage zu verteilten Objekten zu lösen. Leider komm ich noch nicht so richtig klar. Wäre schön wenn mal jemand drüber schaun könnte und mir sagt ob ich soweit auf dem richtigen Weg bin und wo in etwa jetzt noch der Fehler liegt.
Hier der Code für den Server:
Schnittstelle:
und die Gui für den Client:
hier die Ausgabe wenn ich den Client starten will:
C:\Dokumente und Einstellungen\r31eanma\Desktop\ea7>java CountFrame
Exception in thread "main" java.rmi.ConnectIOException: Exception creating conne
ction to: Xxx.Xxx.xxx.xxx; nested exception is:
java.net.NoRouteToHostException: No route to host: 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(Unkn
own Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at $Proxy0.resetCounter(Unknown Source)
at CountFrame.<init>(CountFrame.java:14)
at CountFrame.main(CountFrame.java:78)
Caused by: java.net.NoRouteToHostException: No route to host: 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 S
ource)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
ource)
... 9 more
Danke schon mal
Gruß
versuche grade eine gestellte Aufgage zu verteilten Objekten zu lösen. Leider komm ich noch nicht so richtig klar. Wäre schön wenn mal jemand drüber schaun könnte und mir sagt ob ich soweit auf dem richtigen Weg bin und wo in etwa jetzt noch der Fehler liegt.
Hier der Code für den Server:
Code:
import java.rmi.*;
import java.rmi.server.*;
public class CounterServer {
public static void main(String[] args) throws Exception{
Counter myCounter = new CounterImpl(50);
Naming.rebind("Counter", myCounter);
}
}
class CounterImpl extends UnicastRemoteObject implements Counter{
private int startValue;
private int value;
private int min = 0;
private int max = 99;
public CounterImpl (int start) throws RemoteException {
startValue = start;
value = start;
}
public String incr() {
if (value < max) value++;
return (toString());
}
public String decr() {
if (value > min) value--;
return (toString());
}
public String resetCounter () {
value = startValue;
return (toString());
}
public String toString() { return "" + value; }
}
Schnittstelle:
Code:
import java.rmi.*;
public interface Counter extends Remote{
String incr() throws InterruptedException, RemoteException;
String decr() throws InterruptedException, RemoteException;
String resetCounter () throws InterruptedException, RemoteException;
//public String toString() throws InterruptedException, RemoteException;
}
und die Gui für den Client:
Code:
import java.rmi.*;
import java.awt.*;
import java.awt.event.*;
public class CountFrame extends Frame {
Button bDec = new Button ("<");
Button bInc = new Button (">");
Button bQuit = new Button ("quit");
TextField tCounter = new TextField(3);
Counter c = (Counter) Naming.lookup("rmi://localhost/Counter");
public CountFrame () throws Exception {
tCounter.setEditable(false);
tCounter.setText(c.resetCounter());
// geeignete Beobachter registrieren
bDec.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
try{
tCounter.setText(c.decr());
}
catch (RemoteException r){
System.out.println("RemoteException im Frame");
System.exit (-1);
}
catch (InterruptedException d){
System.out.println("InterruptedException im Frame");
System.exit (-1);
}
}
});
bInc.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
try{
tCounter.setText(c.incr());
}
catch (RemoteException r){
System.out.println("RemoteException im Frame");
System.exit (-1);
}
catch (InterruptedException d){
System.out.println("InterruptedException im Frame");
System.exit (-1);
}
}
});
bQuit.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
try{
tCounter.setText(c.resetCounter());
}
catch (RemoteException r){
System.out.println("RemoteException im Frame");
System.exit (-1);
}
catch (InterruptedException d){
System.out.println("InterruptedException im Frame");
System.exit (-1);
}
}
});
addWindowListener (new WindowAdapter() {
public void windowClosing (WindowEvent e) {
System.exit(0);
}
});
// Komponenten in richtiger Reihenfolge in Panel einfuegen
Panel p = new Panel(new FlowLayout());
p.add (bDec);
p.add (tCounter);
p.add (bInc);
// Komponenten in Hauptfenster einfuegen
add (p, BorderLayout.CENTER);
add (bQuit, BorderLayout.SOUTH);
// Fenstergroesse festlegen
setSize (120, 100);
}
public static void main(String[] args) throws Exception {
CountFrame countFrame = new CountFrame();
countFrame.setVisible(true);
}
}
hier die Ausgabe wenn ich den Client starten will:
C:\Dokumente und Einstellungen\r31eanma\Desktop\ea7>java CountFrame
Exception in thread "main" java.rmi.ConnectIOException: Exception creating conne
ction to: Xxx.Xxx.xxx.xxx; nested exception is:
java.net.NoRouteToHostException: No route to host: 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(Unkn
own Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at $Proxy0.resetCounter(Unknown Source)
at CountFrame.<init>(CountFrame.java:14)
at CountFrame.main(CountFrame.java:78)
Caused by: java.net.NoRouteToHostException: No route to host: 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 S
ource)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
ource)
... 9 more
Danke schon mal
Gruß
Zuletzt bearbeitet: