Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java RMI对象已导出_Java_Rmi - Fatal编程技术网

Java RMI对象已导出

Java RMI对象已导出,java,rmi,Java,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.regi

我在尝试让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    

如果有人能帮忙,那就太好了

删除
UnicastRemoteObject.exportObject()
行。仅当远程对象不扩展UnicastRemoteObject时,才需要它。您可以绑定
服务器
而不是存根。

删除
UnicastRemoteObject.exportObject()
行。仅当远程对象不扩展UnicastRemoteObject时,才需要它。您可以绑定
服务器
而不是存根。

嘿,谢谢。在我执行后仍然会立即关闭。但是有一个不同的异常。嘿,谢谢。在我执行后仍然会立即关闭。但是有一个不同的异常。不要随着解决方案的发展不断更改您的问题。@EJP您在说什么?我只更改了标题。内容仍然是一样的。您将标题更改为完全模糊的内容,这使问题毫无意义,因为问题中没有其他关于实际问题或错误消息是什么的提示。不要随着解决方案的发展不断更改您的问题。@EJP您在说什么我只更改了标题。内容仍然相同。您将标题更改为完全模糊的内容,这使得问题毫无意义,因为问题中没有其他关于实际问题或错误消息的提示。