我已經創建了一個簡單的Java RMI程序來了解它是如何工作的。但是當我嘗試運行我的服務器端時,它引發了以下異常。如何在java程序中解決java.rmi.ConnectException?
編輯:我們正在使用代理服務器連接...
Remote exception: java.rmi.ConnectException: Connection refused to host: 10.7.150.18; nested exception is:
java.net.ConnectException: Connection refused: connect
這是供你參考我的服務器端代碼......
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class SampleServerImpl extends UnicastRemoteObject implements SampleServer
{
SampleServerImpl() throws RemoteException
{
super();
}
@Override
public int sum(int a,int b) throws RemoteException
{
return a + b;
}
public static void main(String[] args)
{
try
{
//set the security manager
//System.setSecurityManager(new RMISecurityManager());
//create a local instance of the object
SampleServerImpl Server = new SampleServerImpl();
//put the local instance in the registry
Naming.rebind("//10.7.150.18:9999" , Server);
System.out.println("Server waiting.....");
}
catch (java.net.MalformedURLException me)
{
System.out.println("Malformed URL: " + me.toString());
}
catch (RemoteException re)
{
System.out.println("Remote exception: " + re.toString());
}
}
}
請指引我走出這個問題...
提供的信息不足。綁定時你得到這個嗎?仰視時?或者當執行遠程方法? – EJP
@EJP:當使用java.exe運行這個文件時 – Saravanan
這實際上並沒有回答我的問題,並且答案就在您應該發佈的堆棧跟蹤中,但是如果您的意思是綁定時發生,那就意味着RMI註冊表不在端口9999上的該主機上運行。 – EJP