View Single Post
  #27 (permalink)  
Old 04-22-2008, 05:20 PM
javarishi javarishi is offline
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
I have made the necessary changes. Try To Compile It.

Interface
----------

import java.rmi.Remote;
import java.rmi.RemoteException;

interface Interface extends Remote{

//Returns the Sum of the Number
public void ReturnSum (String Sum) throws RemoteException;

//Returns the Product of the Number
public void ReturnProduct (String Product) throws RemoteException;

//Returns the Average of the Number
public void ReturnAverage (String Average) throws RemoteException;
}//end Interface


Class
--------

import java.net.*;
import java.io.*;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
import java.rmi.RMISecurityManager;

public class Helper implements Interface {

private final int SIZE =10;
private ASumList sumList[];
private int serverPort;
private int numNumber;
private InetAddress serverHost;
private StreamSocket mySocket;
// private InetAddress serverHost;

public Helper(){
super();

sumList = new ASumList [SIZE];
numNumber = 0;
}

Helper(String hostName,String portNum) throws SocketException,
UnknownHostException, IOException {
this.serverHost = InetAddress.getByName(hostName);
this.serverPort = Integer.parseInt(portNum);
//Instantiates a stream-mode socket and wait for a connection.
this.mySocket = new StreamSocket(this.serverHost, this.serverPort);
System.out.println("Connection request made");

} // end constructor


public String getnumber( String message) throws SocketException, IOException{
String number = "", nextnumber="";;
mySocket.sendMessage( message);

// now receive the names
nextnumber = mySocket.receiveMessage();
while (!nextnumber.equals("")) {
number += nextnumber+" ";
nextnumber = mySocket.receiveMessage();
}
return number;
} // end getnumber


public synchronized int ReturnSum (){
String list ="";
for (int i = 0; i < numNumber; i++)
list = list+ sumList[i].getSum();
list.trim();
return numNumber;
}
public synchronized int Returnproduct(){
String list ="";
for (int i =0;i<numNumber; i++)
list = list+sumList[i].getSum();
list.trim();
return numNumber;
}

public synchronized int ReturnAverage(){
String list ="";
for (int i = 0; i<numNumber; i++)
list = list+sumList[i].getSum();
list.trim();
return numNumber;
}
public void done( ) throws SocketException, IOException{
mySocket.close( );
} // end done

//Returns the Sum of the Number
public void ReturnSum (String Sum) throws RemoteException
{
}
//Returns the Product of the Number
public void ReturnProduct (String Product) throws RemoteException
{
}
//Returns the Average of the Number
public void ReturnAverage (String Average) throws RemoteException
{
}
} //end class

Any Further Queries, let me know.
Reply With Quote