java - RMI 小程序 - 无法理解错误消息

标签 java exception rmi

在我正在编写的一个简单的 RMI 游戏(大学作业)中,我表示:

java.rmi.MarshalException: error marshalling arguments; nested exception is:
        java.net.SocketException: Broken pipe
        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:138)
        at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
        at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
        at $Proxy2.drawWorld(Unknown Source)
        at PlayerServerImpl$1.actionPerformed(PlayerServerImpl.java:180)
        at javax.swing.Timer.fireActionPerformed(Timer.java:271)
        at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

The error message appears after the second Player is registered with the RMI Server and the server starts to send the image (the array of pixels) to the 2 applets. The PlayerImpl and the PlayerServerImpl both extend UnicastRemoteObject.

I have been struggling with other error messages for some time now, but I cannot understand how to troubleshoot this one. Please help.

The relevant parts of the code are:

PlayerServerImpl.java:


                        ...
        timer = new Timer(10, new ActionListener() { // every 10 milliseconds do:
            @Override
            public void actionPerformed(ActionEvent e) {
                        ...
                    BufferedImage buff_image = new BufferedImage(GAME_APPLET_WIDTH, GAME_APPLET_HEIGHT, BufferedImage.TYPE_INT_RGB);
                    // create a graphics context on the buffered image
                    Graphics buff_g = buff_image.createGraphics();
                        ...
                    // draw the score somewhere on the screen
                    buff_g.drawString(score, GAME_APPLET_WIDTH - 20, 10);
                        ...
                    int[] rgbs = new int[GAME_APPLET_WIDTH * GAME_APPLET_HEIGHT];
                    int imgPixelsGrabbed[] = buff_image.getRGB(0,0,GAME_APPLET_WIDTH,GAME_APPLET_HEIGHT,rgbs,0,GAME_APPLET_WIDTH);
                    // send the new state to the applets
                    for (Player player : players) {
                        player.drawWorld(imgPixelsGrabbed);
                        System.out.println("Sent image to player");
                    }

PlayerImpl.java:


    private PlayerApplet applet;    

    public PlayerImpl(PlayerApplet applet) throws RemoteException {
        super();
        this.applet = applet;
    }
        ...
    @Override
    public void drawWorld(int[] imgPixelsGrabbed) throws RemoteException {
        applet.setWorld(imgPixelsGrabbed);
        applet.repaint(); 
    }
        ...

PlayerApplet.java:


        ...
    private int[] world; // an array of pixels for the new image to be drawn
        ...
        // register players
                player = new PlayerImpl(applet);
                String serverIPAddressPort = ipAddressField.getText();
                if (validateIPAddressPort(serverIPAddressPort)) {
                    server = (PlayerServer) Naming.lookup("rmi://"
                            + serverIPAddressPort + "/PlayerServer");
                    server.register(player);
                    idPlayer = server.sendPlayerID();
        ...
    @Override
    public void update(Graphics g) {
        buff_img = createImage((ImageProducer) new MemoryImageSource(getWidth(), getHeight(), world, 0, getWidth()));
        Graphics gr = buff_img.getGraphics();
        paint(gr);
        g.drawImage(buff_img, 0, 0, this);
    }

    public void setWorld(int[] world) {
        this.world = world;
    }

最佳答案

我已经重写了整个事情。我多次收到相同的错误消息,每次都表明网络问题。所以我想问题已经解决了。

关于java - RMI 小程序 - 无法理解错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2728805/

相关文章:

java - 使用内存中的 CSV 数据源生成 Jasper 报告报告

java - 抽象工厂模式接口(interface)实现或类扩展

C# Throw 被最后一次捕获

java - Spring - 通过 RMI 传递监听器

java - Java 中对 IPC 的 RMI 支持

java - 如何使用 Java RMI 从 Windows 服务控制桌面窗口?

JavaFX独立旋转NumberAxis

java - 访问 java .properties 文件中的系统属性

ios - 使用我自己的广告单元 ID 时 AdMob 崩溃

java - 捕获异常后 for 循环继续出现问题