Want to Invoke Object Method without start RMISERVER

HI Friends,

I am Ravi developing my Application in RMI. I have make my application like this:

There is a client and server architecture. On Server RMI Server is running with rmiregistry. From client I'm invoking a RMI method on server which runs parfectly and gives the result on server only.

Now I want that The result which is coming on server It should be come on client so I am going to make another Remote Method on Client and will be invoking this method from server so the result would be on client. The structure would be like this :

Client -> Server -> Client.

But Here I don't want to run rmiregistry and RMI Server on client side. How I can do like this.

I think i tried best to explain it....

Thanks in advance.

[782 byte] By [Ravijia] at [2007-11-26 19:08:09]
# 1

You have to run an RMI server on the client side, otherwise the server can't call the client. But you don't have to run the Registry at the client. Instead you can do something like this:

server.registerCallback(clientCallback);

where clientCallback is the remote object at the client that the server needs to call. The server must save the callback reference supplied and call it when it wants to.

ejpa at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 2
ejp is right, you should use callbacks. Do a google search for Java RMI Callback and you should find some good examples.
carr_onstotta at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 3
Well it's not that he should use callbacks, he has already decided to use callbacks, but he doesn't want to go through the export process which is necessary.He just has to decide between these irroncilable objectives.
ejpa at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 4

Thanx ejp and all for valuable replies....

but when i'm using this line in my program it is giving error....Actually I don't know how to know it....

Error is:

java:54: cannot resolve symbol

symbol : method registerCallback (java.lang.String)

location: class java.lang.String

thisAddress.registerCallback("rmiserver");

Ravijia at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 5

You have to define this callback-registration method, whatever you want to call it, in your IDL or your remote interface, and you have to implement it too. It's not built-in. And it needs a reference to the remote callback object as its parameter, not a String. Your server has to store that reference somewhere and use it to callback the client method, whatever that is.

If you had googled on Java RMI callback, as suggested 18 hours ago, you would probably have figured all this out by now.

ejpa at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 6

Hi Ejp, can you help me out to do this.....here I'm giving my code :

My Interface:

import java.rmi.*;

public interface ReceiveMessageInterface extends Remote {

void getInfo(String phno, String IP) throws RemoteException;

}

My Client :

import java.rmi.*;

import java.rmi.registry.*;

import java.net.*;

public class RmiClient

{

static public void main(String args[])

{

ReceiveMessageInterface rmiServer;

Registry registry;

String serverAddress=args[0];

String serverPort=args[1];

String phonenum=args[2];

String IPaddress=args[3];

System.out.println("Calling Method with "+phonenum+" and "+IPaddress+" on "+serverAddress+":"+serverPort);

try{

// get the 搑egistry?br>System.out.println("Calling....");

registry=LocateRegistry.getRegistry(serverAddress,(new Integer(serverPort)).intValue());

// look up the remote object

rmiServer=(ReceiveMessageInterface)(registry.lookup("rmiServer"));

// call the remote method

System.out.println("Remoted Method Called !");

rmiServer.getInfo(phonenum,IPaddress);

}

catch(RemoteException e){

e.printStackTrace();

}

catch(NotBoundException e){

e.printStackTrace();

}

}

}

My Server:

import java.rmi.*;

import java.rmi.registry.*;

import java.rmi.server.*;

import java.net.*;

import java.sql.*;

import java.io.*;

public class RmiServer extends java.rmi.server.UnicastRemoteObject implements

ReceiveMessageInterface

{

int thisPort;

StringthisAddress;

Registry registry;// rmi registry for lookup the remote objects.

// This method is called from the remote client by the RMI.

// This is the implementation of the 揜eceiveMessageInterface?

public void getInfo(String phno, String IP) throws RemoteException {

try {

System.out.println("Phone Number: "+phno);

String url="jdbc:mysql://localhost:3306/test?user=root&password=myserver";

Connection con=null;

ResultSet rst=null;

Statement stmt=null;

Class.forName("com.mysql.jdbc.Driver").newInstance();

con = DriverManager.getConnection(url);

stmt = con.createStatement();

rst = stmt.executeQuery("Select * from dispositionreport");

while(rst.next()) {

System.out.println(rst.getString("campaigne"));

System.out.println(rst.getString("username"));

System.out.println(rst.getString("disposition"));

}

System.out.println("IP Address: "+IP);

}catch(Exception e) {

System.out.println("Connection Error: "+e);

}

}

public RmiServer() throws RemoteException {

try{

// get the address of this host.

thisAddress= ("192.168.0.*");

//thisAddress= (InetAddress.getLocalHost()).toString();

}catch(Exception e){

throw new RemoteException("can't get inet address.");

}

thisPort=8367; // this port(registry抯 port)

System.out.println("This Address="+thisAddress+",Port="+thisPort);

try{

// create the registry and bind the name and object.

registry = LocateRegistry.createRegistry( thisPort );

registry.rebind("rmiServer", this);

} catch(RemoteException e){

throw e;

}

}

static public void main(String args[]){

try{

RmiServer s=new RmiServer();

}catch (Exception e) {

e.printStackTrace();

System.exit(1);

}

}

}

From this Please tell me How should I do and what should I do?

Thanx in advance....

Ravijia at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 7
********************************REFRESH**********************************
Ravijia at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 8
> If you had googled on Java RMI callback, as suggested> 18 hours ago, you would probably have figured all this out by now.Four days later and you still haven't taken this advice?
ejpa at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 9
Hi ejp,I google it for RMI Callback but still I'm confused....might be my problem but can u help me.....pleeeeeeeeeeeee
Ravijia at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 10

I think the confusion here is that you think you need to call the client from the server, when you most probably don't have to do that at all.

We answered your original question about how to make a callback in the client and call it, but looking at it again, your original question is probably wrong.

Isn't all you're trying to do just to get the result of getInfo() back to the client? In which case all you have to do is declare it to return some object type, change the implementation to return it; and change the call in the client to store the returned value. No callbacks, no Google, nothing but normal Java syntax.

ejpa at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 11

> Hi Ejp, can you help me out to do this.....here I'm

> giving my code :

>

> My Interface:

>

> import java.rmi.*;

>

> public interface ReceiveMessageInterface extends

> Remote {

> void getInfo(String phno, String IP) throws

> s RemoteException;

> }

>

Why not change that interface to

public interface ReceiveMessageInterface extends Remote {

String [] getInfo(String phno, String IP) throws RemoteException;

}

Then return the array of strings directly from that method.

_dnoyeBa at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 12

Thanx for the reply but I think It is my fault that I didn't make it clear :

Actually It is like this :

"ClientOne will throw some input on Server and server will catch it and wil throw it on ClientTwo."

Means Server will take PhoneNumber and IPAddress from ClientOne and will throw PhoneNumber on taken IPAddress. e.g. Server is taking input 2384023(PhoneNumber), 192.168.1.110(IPAddress) then after taking it it will throw PhoneNumber on 192.168.1.110 IPAddress.

I think now i have tried my best to explain this problem..:)

Thanx in advance....

Ravijia at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 13
Ejp where are you?Any one can help me?
Ravijia at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 14

OK, since you are talking callback, lets take the callback approach.

public interface ReceiveMessageInterface extends Remote {

public void getInfo(String phno, String IP) throws RemoteException;

public void putCallback(ICallBack secondClient) throws RemoteException;

}

The first client calls the first method, the 2nd client calls the 2nd method. The server will use the interface passed into ICallBack to pass the data onto the 2nd client. That interface should have some method that allows the server to send it the data you want passed to the 2nd client.

_dnoyeBa at 2007-7-9 21:01:22 > top of Java-index,Core,Core APIs...
# 15
Hi _dnoyeB,Thanx for your valuable reply and good effort, I will try on it and will get back to you if I face any problem.
Ravijia at 2007-7-9 21:01:30 > top of Java-index,Core,Core APIs...
# 16

Hi List,

Now I'm totally puzzle, How to do it because I am doing hard work on it and not getting proper result....I don't know how to do it?

Please anyone can tell me that on net where I can get example like this so that I can go through that and can understand? OR can anyone send me the coding for the same?

ple ple help me......

Thanx in advance.....

Ravijia at 2007-7-9 21:01:30 > top of Java-index,Core,Core APIs...
# 17

Hi Ejp and others,

I have solve my problem but in a different way..What i did that:

I will send the IPAddress and PhoneNumber to the Server, Server will read the IPAddress and will send that information related to phonenumber on particulate IPAddress.

But Still I want to know that how we can solve above problem....

Thanx

Ravijia at 2007-7-9 21:01:30 > top of Java-index,Core,Core APIs...
# 18

the server should store the 'secondClient' reference. And when the server is done with its calculation, it should then invoke a method on that reference to pass in the data.

Of course it the second client reference was set 'after' the calculation completed, then the server does not have to store it but just send the data back right away. This is not so much an RMI question but a general question. You should familiarize yourself with the observer/observable pattern.

_dnoyeBa at 2007-7-9 21:01:30 > top of Java-index,Core,Core APIs...