RMI-applets - 无法理解错误消息

时间:2010-04-28 11:01:21

标签: 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)

在向RMI服务器注册第二个Player并且服务器开始将图像(像素数组)发送到2个applet后,将显示错误消息。 PlayerImpl和PlayerServerImpl都扩展了UnicastRemoteObject。

我一直在努力解决其他错误消息,但我无法理解如何解决这个问题。请帮忙。

代码的相关部分是:

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;
    }

1 个答案:

答案 0 :(得分:0)

我重写了整件事。我多次收到相同的错误消息,并且每次都指示网络问题。所以我想这个问题已经解决了。