我遇到了一個嘗試讓RMI工作的問題。我有註冊表運行,當我嘗試啓動服務器時,一個窗口彈出不到一秒鐘,然後關閉。這是爲什麼發生。已導出RMI對象
服務器軟件包--- MyFileServer.java
package Server;
import java.io.File;
import java.io.FileInputStream;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
/**
* Created by alexi on 05/12/2016.
*/
public class MyFileServer extends UnicastRemoteObject implements ServerInit {
protected MyFileServer() throws RemoteException {
super();
}
@Override
public void importFiles(Notify n, String name) throws RemoteException {
String videoPath = "src" + File.separator + "Videos" + File.separator + name;
try {
File video = new File(videoPath);
FileInputStream in=new FileInputStream(video);
byte [] mydata=new byte[(int)video.length()+1];
int mylen=in.read(mydata);
while(mylen>0){
n.sendData(video.getName(), mydata, mylen);
mylen=in.read(mydata);
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args){
try{
ServerInit server = new MyFileServer();
ServerInit stub = (ServerInit) UnicastRemoteObject.exportObject(server, 0);
Registry registry = LocateRegistry.getRegistry();
registry.bind("videoServer", stub);
}catch (RemoteException e){
e.printStackTrace();
} catch (AlreadyBoundException e) {
e.printStackTrace();
}
}
}
像這樣運行它。
start java -classpath E:\Documents\Development\Projects\OOP3_Project1\bin\Server/ -Djava.rmi.codebase=file:/E:\Documents\Development\Projects\OOP3_Project1\bin\Server/ MyFileServer
如果有人可以幫助將是巨大的
隨着解決方案的發展,不要隨時改變您的問題。 – EJP
@EJP你在說什麼,我只是改了標題。內容仍然相同 –
您將標題更改爲完全模糊的標題,這使問題完全沒有意義,因爲在問題中沒有提供有關實際問題或錯誤消息的其他提示。 – EJP