java.rmi.ConnectException: Connection refused to host: 10.0.0.100; 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.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at guiproject.AddClient.main(AddClient.java:12)
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)
... 6 more
import java.rmi.*;
public interface AddServerIntf extends Remote {
double add(double d1, double d2) throws Exception;
}
import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf{
public AddServerImpl() throws RemoteException{
}
public double add(double d1, double d2) throws RemoteException{
return d1 + d2;
}
public static void main(String args[]){
}
}
public class AddServer {
public static void main(String args[]){
try{
AddServerImpl addServerImpl = new AddServerImpl();
Naming.rebind("AddServer", addServerImpl);
}
catch(Exception e){
e.printStackTrace();
}
}
}
//the client side
public class AddClient {
public static void main(String args[]){
try{
Scanner in = new Scanner(System.in);
String addServerURl = "rmi://" + "/AddServer";
AddServerIntf addServerintf = (AddServerIntf)Naming.lookup(addServerURl);
System.out.println("The first Numer is :");
double d1 = in.nextDouble();
System.out.println("The second number is:");
double d2 = in.nextDouble();
System.out.println("The sum is:" +addServerintf.add(d1,d2));
}
catch(Exception e){
e.printStackTrace();
}
}
}
クライアント側に接続するたびに、この例外が発生します。Connection 例外に関するいくつかの資料を読みましたが、解決策はどれも機能していないようです。// リクエストに応じてコードも上に貼り付けられます。うまくいくことを願っています...