passing parameters by reference in RMI
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Srihari_Madala
Posted On:   Wednesday, May 1, 2002 04:13 AM

Can you tell how to pass parameters by reference in RMI.Can you give one source code example. I know that the parameters should be remote objects when they are to be passed by reference. But I want to see one example.Please reply to this.

Re: passing parameters by reference in RMI

Posted By:   Omer_Mahmood  
Posted On:   Friday, May 10, 2002 09:31 PM


public class Client
{
public static void main(String args[])
{
Server server;
try
{
server = (Server) java.rmi.Naming.lookup("//INFORMATICSPC12/ObjRef");


System.out.print("Message From the server is : ");

System.out.println(server.getMessage());

if(args.length > 0)
{
System.out.println("New Message Set");

server.setMessage(args[0]);

System.out.println(server.getMessage());
}
}
catch(java.rmi.NotBoundException e)
{}
catch(java.rmi.RemoteException e)
{}
catch(java.net.MalformedURLException e)
{}
}
}


SERVER


public class ServerImpl extends java.rmi.server.UnicastRemoteObject implements Server
{
String message = "";


public ServerImpl() throws java.rmi.RemoteException
{
super();
}

public static void main(String args[]) throws java.rmi.RemoteException
{
Server me = new ServerImpl();

try
{
java.rmi.Naming.rebind("//INFORMATICSPC12/ObjRef",me);
}
catch(java.net.MalformedURLException e)
{
e.printStackTrace();
}
}

public void setMessage(String message) throws java.rmi.RemoteException
{
this.message = message;
}

public String getMessage() throws java.rmi.RemoteException
{
return message;
}
}
Interface


public interface Server extends java.rmi.Remote
{
void setMessage(String message) throws java.rmi.RemoteException;
String getMessage() throws java.rmi.RemoteException;
}
About | Sitemap | Contact