Remote Shutdown using RMI
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ajay_kemparaj
Posted On:   Sunday, April 2, 2006 11:15 AM

<! ┬áCan any one help to execute the following code ...I t has 4 parts ...got it from the web .... Try this program interface.java import java.rmi.*; import java.rmi.server.*; public interface intf extends Remote { public void shutdown() throws RemoteException; } Implementation Java file import java.util.*; import java.io.*; import java.rmi.*; import java.rmi.server.*; public class Serverimpl extends UnicastRemoteObject implements intf { public Serverimpl() throws RemoteException {} public void shutdown() {    More>>
<!

 Can any one help to execute the following
code ...I t has 4 parts ...got it from the web
....


Try this program

interface.java

import java.rmi.*;
import
java.rmi.server.*;
public interface intf extends Remote
{
public void
shutdown() throws RemoteException;
}

Implementation Java
file

import java.util.*;
import java.io.*;
import
java.rmi.*;
import java.rmi.server.*;
public class Serverimpl extends
UnicastRemoteObject implements intf
{
public Serverimpl() throws
RemoteException
{}
public void shutdown()
{
try
{
Runtime rt =
Runtime.getRuntime();
Process proc = rt.exec("shutdown
-l");
}
catch(Throwable
t)
{
t.printStackTrace();
}
}
}

Server Java
file

import java.rmi.*;
import java.rmi.server.*;
public class
Server
{
public static void main(String arg[]) throws
Exception
{
Serverimpl impl = new
Serverimpl();
System.out.println("Initialising
server.........");
Naming.rebind("rajesh",impl);
System.out.println("Registered");
}
}


Client
java file

import java.rmi.*;
import java.rmi.server.*;
public class
Client
{
public static void main(String args[]) throws
Exception
{
String url = "rmi://192.0.0.100/rajesh";
intf intf1 =
(intf)Naming.lookup(url);
intf1.shutdown();
}
}

the change you
have to make that instead of using the string url "192.0.0.100" you have to give
the url of your computer in which the server programe is
running.

   <<Less
About | Sitemap | Contact