RemoteInterface.java import java.rmi.

*; public interface RemoteInterface extends Remote { public int add(int x,int y)throws Exception; } ServerImplements.java import java.rmi.*; import java.rmi.server.*; import java.lang.String; interface RemoteInterface extends Remote { public int add(int x, int y) throws Exception; } public class ServerImplements extends UnicastRemoteObject implements RemoteInterface { public ServerImplements() throws Exception { super(); } public int add(int x, int y) { return (x + y); } } Server.java import java.rmi.*; import java.net.*; public class Server { public static void main(String args[]) { try { ServerImplements s = new ServerImplements(); Naming.rebind("RMIAPPLICATION", s); System.out.println("Server has been started"); } catch (Exception e) { System.out.println(e.getMessage()); } } } Client.java import import import import import java.rmi.*; java.awt.*; java.awt.event.*; java.io.*; javax.swing.*;

public class Client extends JFrame { TextField t1 = new TextField(30); TextField t2 = new TextField(30); Label rs = new Label("Sum= 0"); JButton b = new JButton("Add"); Panel p = new Panel(new GridLayout(4, 1, 5, 5)); RemoteInterface s;

b).add(a. try { String ipp = JOptionPane . } catch (Exception epx) { } } }). rs.setDefaultCloseOperation(EXIT_ON_CLOSE). int b = Integer. c.lookup(ip). } catch (Exception exp) { JOptionPane. p. 250). exp.parseInt(t2.showInputDialog("Please enter the IP Address to Connect").setVisible(true).getMessage()). p.add(t1). "North").getText()). } b.setText("Sum of two no =" + r). 300).add(b). p.parseInt(t1.public Client() { super("Client Side"). try { int r = s. s = (RemoteInterface) Naming.add(rs).getText()). String ip = "rmi://" + ipp + "/RMIAPPLICATION".add(p.add(t2). } public static void main(String args[]) { Client c = new Client(). p. setSize(250. c. getContentPane(). setLocation(300.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int a = Integer. } } .showMessageDialog(null.

Sign up to vote on this title
UsefulNot useful