Hello,
I run the server.java and client.java on
ONE PC with the IP *192.168.1.4*
Why do i get this:
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 192.168.1.4; 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.lookup(Unknown Source)
at Client.main(Client.java:11)
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
public class Client
{
public static void main( String[] args ) throws RemoteException, NotBoundException
{
Registry registry = LocateRegistry.getRegistry();
Adder adder = (Adder) registry.lookup( "Adder" );
System.out.println( adder.add( 50, 10 ) );
}
}
public class Server
{
public static void main( String[] args ) throws RemoteException
{
LocateRegistry.createRegistry( Registry.REGISTRY_PORT );
AdderImpl adder = new AdderImpl();
Adder stub = (Adder) UnicastRemoteObject.exportObject( adder, 0 );
RemoteServer.setLog( System.out );
Registry registry = LocateRegistry.getRegistry();
registry.rebind( "Adder", stub );
System.out.println( "Adder angemeldet" );
}
}
public interface Adder extends Remote
{
int add( int x, int y ) throws RemoteException;
}
public class AdderImpl implements Adder
{
public int add( int x, int y )
{
return x + y;
}
}