Hi, I want to write an application to share desktop between client and server with java rmi. This is the interface:
public interface IServer extends Remote{
public void share(BufferedImage image) throws RemoteException;
}
-----------------------------
// This is the server side code:
public class ServerFrame extends JFrame implements IServer{
public static void main(String args[]) {
try {
ServerFrame frame = new ServerFrame();
frame.setVisible(true);
LocateRegistry.createRegistry(1099);
Naming.bind("test", frame);
System.out.println("Server Started Successfully...");
} catch (Exception e) {
e.printStackTrace();
}
}
. . .
public ServerFrame() {
super();
try {
UnicastRemoteObject.exportObject((Remote) this);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
. . . // bulding the ServerFrame GUI
. . .
public void share(BufferedImage image) throws RemoteException {
label.setIcon(new ImageIcon(image));
}
}
---------------
// And finally this is the client side: there is a button in the ClientFrame which I want the desktop to be shared between client and server after I clicked this button.
public class ClientFrame extends JFrame implements Remote,Serializable{
IServer serve;
...
public ClientFrame() {
super();
try {
serve = (IServer) Naming.lookup("test");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (NotBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
. . . // codes for building client gui
final JButton shareDesktopButton = new JButton();
shareDesktopButton.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent arg0) {
try {
BufferedImage screenShot = new Robot()
.createScreenCapture(new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize()));
label.setIcon(new ImageIcon(screenShot));
serve.share(screenShot);
} catch (HeadlessException e) {
e.printStackTrace();
} catch (AWTException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
});
. . .
}
// but there is a problem that causes these exceptions that I can not understand it. Please help me to complete my project.
Thanks a lot
Exceptions:
java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: java.awt.image.BufferedImage
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at server.ServerFrame_Stub.share(Unknown Source)
at client.ClientFrame$1.mouseClicked(ClientFrame.java:86)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.io.NotSerializableException: java.awt.image.BufferedImage
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at sun.rmi.server.UnicastRef.marshalValue(Unknown Source)
... 24 more