[英]how to find rmi server address on local machine?
I want to create simple RMI program for client and server to get the date from the server. 我想为客户端和服务器创建简单的RMI程序,以从服务器获取日期。 My server code is compiling but while running I am getting this error: Invalid URL String Caused by: java.net.URISyntaxException: Illegal character in path at index 4: Da te Server
我的服务器代码正在编译,但是在运行时出现此错误:URL字符串无效原因:java.net.URISyntaxException:索引4的路径中的字符非法:数据服务器
Code: 码:
// IDate.java
import java.rmi.*;
public interface IDate extends Remote{
String getDate() throws RemoteException;
}
// DateImpl.java
import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
public class DateImpl extends UnicastRemoteObject implements IDate{
public DateImpl() throws RemoteException{}
public String getDate(){
Date d=new Date();
return(d.toString());
}}
// DateServer.java
import java.rmi.*;
public class DateServer{
public static void main(String[] args){
try{
DateImpl di=new DateImpl();
Naming.rebind("DateServer",di);
System.out.println("Date Server is Ready");
}
catch(Exception e){
e.printStackTrace();
}}}
// DateClient.java
import java.rmi.*;
public class DateClient{
public static void main(String[] args)
{
try{
String url="rmi://127.0.0.1/DateServer";
IDate intf=(IDate)Naming.lookup(url);
System.out.println("The Date On Server is: "+intf.getDate());
}
catch(Exception e){
e.printStackTrace(); } } }
java.net.URISyntaxException: Illegal character in path at index 4: Da te Server
...
Naming.rebind("DateServer",di);
Obviously that isn't the real code. 显然,这不是真正的代码。 In any case it should be
无论如何应该
Naming.rebind("rmi://localhost/DateServer",di);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.