I'm having problems closing the server component and hope to get help.
My server code is as follows: it has a way to shut down the server
Server
private final String address = "127.0.0.1"; private Registry registry; private int port = 6789; public RmiServer() throws RemoteException { try { registry = LocateRegistry.createRegistry(port); registry.rebind("rmiServer", this); } catch (RemoteException e) { logger.error("Unable to start the server. Exiting the application.", e); System.exit(-1); } } public void shutDownServer() throws RemoteException { int succesful = 0; try { registry.unbind("rmiServer"); UnicastRemoteObject.unexportObject(this, true); Thread.sleep(1000); } catch (NotBoundException e) { logger.error("Error shutting down the server - could not unbind the registry", e); succesful = -1; } catch (InterruptedException e) { logger.info("Unable to sleep when shutting down the server", e); succesful = -1; } catch (AccessException e) { logger.info("Access Exception", e); succesful = -1; } catch (UnmarshalException e) { System.out.println(e.detail.getMessage()); logger.info("UnMarshall Exception", e); succesful = -1; } catch (RemoteException e) { System.out.println(e.detail.getMessage()); logger.info("Remote Exception", e); succesful = -1; } logger.info("server shut down gracefully"); System.exit(succesful); }
My client connects perfectly, no problem, so to complete the work I created a new application, copied the client code for the connection and then called the close method on the server
Shutdown
open class Shutdown {
private String serverAddress = "127.0.0.1"; private String serverPort = "6789"; private ReceiveMessageInterface rmiServer; private Registry registry; public Shutdown(){ try { registry = LocateRegistry.getRegistry(serverAddress, (new Integer(serverPort)).intValue()); rmiServer = (ReceiveMessageInterface) (registry.lookup("rmiServer")); logger.info("Client started correctly"); rmiServer.shutDownServer(); System.exit(0); } catch (UnmarshalException e ){ logger.error("Unmarshall exception. Exiting application", e); System.exit(-1); } catch (RemoteException e) { logger.error("Remote object exception occured when connecting to server. Exiting application", e); System.exit(-1); } catch (NotBoundException e) { logger.error("Not Bound Exception occured when connecting to server. Exiting application", e); System.exit(-1); } }
No matter what I try, I get the following exception:
ERROR com.rmi.client.RMIClient - Unmarshall exception. Exiting application java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: java.net.SocketException: Connection reset at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source) at sun.rmi.server.UnicastRef.invoke(Unknown Source) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source) at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source) at $Proxy0.shutDownServer(Unknown Source) at com.rmi.shutdown.Shutdown.<init>(Shutdown.java:31) at com.rmi.shutdown.Shutdown.main(Shutdown.java:52) Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(Unknown Source) at java.io.BufferedInputStream.fill(Unknown Source) at java.io.BufferedInputStream.read(Unknown Source) at java.io.DataInputStream.readByte(Unknown Source) ... 7 more
I believe that this may be due to the fact that the client is not disconnected properly and just βdisconnectedβ, but I'm not sure how to disconnect the server side yet?
Please, can someone advise.
thanks