【发布时间】:2018-08-25 15:26:20
【问题描述】:
我正在尝试在 RMI 中编写一个从服务器程序复制文件的客户端程序:
FileClientInt 接口
public interface FileClientInt extends Remote {
public boolean sendData(String fileName, byte[] data, int len) throws RemoteException;
public String getName() throws RemoteException;
}
FileServerInt 接口
public interface FileServerInt extends Remote {
public boolean login(FileClientInt c) throws RemoteException;
}
文件客户端类
public class FileClient extends UnicastRemoteObject implements FileClientInt {
/**
*
*/
private static final long serialVersionUID = 1L;
public String name;
public FileClient(String n) throws RemoteException {
super();
name = n;
}
public String getName() throws RemoteException {
return name;
}
public boolean sendData(String filename, byte[] data, int len) throws RemoteException {
try {
File f = new File(filename);
f.createNewFile();
FileOutputStream out = new FileOutputStream(f, true);
out.write(data, 0, len);
out.flush();
out.close();
System.out.println("Done writing data...");
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
StartFileClient 类
public class StartFileClient {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
FileClient c = new FileClient("out.txt");
FileServerInt server = (FileServerInt) Naming.lookup("rmi://192.168.2.15");
server.login(c);
System.out.println("Listening.....");
Scanner s = new Scanner(System.in);
while (true) {
String line = s.nextLine();
}
} catch (Exception e) {
System.out.println("Error " + e.getMessage());
}
}
它给了我错误:
Error sun.rmi.registry.RegistryImpl_Stub cannot be cast to myfileclient.FileServerInt
我该如何解决这个错误?任何机构都可以帮助解决这个问题吗?
【问题讨论】:
标签: java registry rmi classcastexception stub