2010-04-28 4 views
1

Dans un jeu simple RMI j'écris (une affectation en uni), je reveice:RMI-applets - Impossible comprendre le message d'erreur

 
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) 

Le message d'erreur apparaît après le deuxième joueur est enregistré auprès du RMI Le serveur et le serveur commencent à envoyer l'image (le tableau de pixels) aux 2 applets. PlayerImpl et PlayerServerImpl étendent UnicastRemoteObject.

Je suis aux prises avec d'autres messages d'erreur depuis un certain temps, mais je n'arrive pas à comprendre comment résoudre ce problème. S'il vous plaît aider.

Les parties pertinentes de ce code sont:

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

Répondre

0

J'ai réécrit le tout. J'ai reçu le même message d'erreur plusieurs fois, et chaque fois qu'il indiquait un problème de réseau. Donc je suppose que la question est résolue.

Questions connexes