views:

64

answers:

1

In a simple RMI game I'm writing (an assignment in uni), I reveice:

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

I have rewritten the whole thing. I have received the same error message several times, and every time it was indicating a network problem. So I guess the question is solved.

aeter