-
- Go to the path where java files are stored.
- Compile all java files =>
javac *.java
- Create Stub and Skelton =>
rmic AddC
- Start server =>
java Server
-
- Start Client =>
java Client
Last active
February 29, 2020 09:54
-
-
Save ats1999/7afa7352b9106cb8a6a63597dc98a288 to your computer and use it in GitHub Desktop.
Web Application design and development (Rahul kumar)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rmi; | |
/** | |
* This file contains class which have implemention of AddI interface | |
*/ | |
import java.rmi.RemoteException; | |
import java.rmi.server.UnicastRemoteObject; | |
/** | |
* This class defines add method, which is called by the client. | |
* @version 1.0 | |
* @author Rahul kumar | |
* | |
*/ | |
public class AddC extends UnicastRemoteObject implements AddI{ | |
/** | |
* This is constructor. This constructor will call parent class | |
* constructor indirectly. | |
* @throws RemoteException | |
*/ | |
protected AddC() throws RemoteException { | |
super(); | |
} | |
/** | |
* This method will return sum of both arguments. | |
* @param x first number | |
* @param y second number | |
* @return x+y result | |
* @throws Exception | |
*/ | |
@Override | |
public int add(int x, int y) throws Exception { | |
return x+y; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rmi; | |
/** | |
* This file contains interface AddI. | |
*/ | |
import java.rmi.Remote; | |
/** | |
* This interface contains method AddI. | |
* @version 1.0 | |
* @author Rahul kumar | |
* | |
*/ | |
public interface AddI extends Remote{ | |
/** | |
* This method accepts two integer arguments. | |
* This method return an integer number. | |
* @param x first number. | |
* @param y second number | |
* @return number( result) | |
* @throws Exception | |
*/ | |
public int add(int x,int y) throws Exception; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rmi; | |
/** | |
* This package contains client class. | |
*/ | |
import java.rmi.Naming; | |
/** | |
* This class represent Client. | |
* Thsi class will call method add, from the server. | |
* @class Client | |
* @author Rahul kumar | |
* | |
*/ | |
public class Client { | |
/** | |
* This is main method. | |
* @param args unused | |
* @throws Exception | |
*/ | |
public static void main(String[] args) throws Exception{ | |
//search for the method add by looking the reference "ADD" | |
AddI obj=(AddI)Naming.lookup("ADD"); | |
// call the method | |
int sum=obj.add(5, 5); | |
// print the result | |
System.out.println("Sum is : "+sum); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rmi; | |
/** | |
* @author Rahul kumar | |
* This has server class which represent remote server. | |
*/ | |
import java.rmi.Naming; | |
/** | |
* @class Server | |
* @version 1.0 | |
* This class will provide service to the client. | |
*/ | |
public class Server { | |
/** | |
* This method will serve client. | |
* @param args unused | |
* @throws Exception | |
*/ | |
public static void main(String[] args) throws Exception{ | |
// create object of AddC | |
AddC obj=new AddC(); | |
// bind this object with "ADD", this object will be referenced by "ADD" | |
Naming.rebind("ADD", obj); | |
// print message ... | |
System.out.println("SERVER.........STARTED"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment