GeeCON Prague 2014*
The moose likes Distributed Java and the fly likes rmi callback Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Distributed Java
Bookmark "rmi callback" Watch "rmi callback" New topic
Author

rmi callback

simranjit singh
Greenhorn

Joined: Mar 01, 2007
Posts: 12
my client is able to use functions stored in server thru rmi.. but i am not able to make calls from server to client.. will be glad if anyone can explain this with an easy example

thnx..
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Originally posted by simranjit singh:
my client is able to use functions stored in server thru rmi.. but i am not able to make calls from server to client.. will be glad if anyone can explain this with an easy example

thnx..

When you say you are "not able to", it means that you get an exception or you can not figure out how to do that?
Well, if there is an exception then a stacktrace will help however, if you can not figure it out, then, the point is that the client should also expose its Remote interface for others(server) to call it.
So, in this scenario, there is no clear role separation of a client and server, both the objects act as both client and server.


apigee, a better way to API!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
... so the question becomes: Is the client set up to act as an RMI server as well?


Ping & DNS - my free Android networking tools app
simranjit singh
Greenhorn

Joined: Mar 01, 2007
Posts: 12
i can not figure out how to do that...

i tried but i landed up writing my output message on server sides cmd prompt(that according to me should have been printed on client sides cmd prmpt) and if i try putting up my that message in my client sides window,(textarea) it gives me nullpointer and for this i know why since it could not find a reference to that client window in which it should print.

server code:


server Interface:


client:


client interface file:


login file m using:



will be glad if you people can tellme where i am going wrong or what i can do to correct my code..

thanks
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

I am not very sure whether this code runs with the client and server running in two different JVMs.
Well, i do not have any idea about Swing, but i am very skeptical about this code:


What you are doing is that you are exporting a different object (Instance 1)and registering a different object with the server(Instance 2).
This can only work when, the client and server are running in the same jvm when the actual instance of the client is passed to the server instead of the stub. Otherwise, it should give a Marshalling exception.
Anyways, i think if you pass instance 1 in the registerForCallback method, it should work.
I leave it to you to find out as to why, the message you expected to print on the client was printing on the server(assuming they run on same JVM)
simranjit singh
Greenhorn

Joined: Mar 01, 2007
Posts: 12


used this.. again the null pointer exception.. i cannot figure out where i am going wrong..


this jtextArea is giving error


Stacktrace :


problem of getting that message on server window has been solved.. thanks alot..
will be glad if this nullpointer can also be removed..
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Firstly, adding to my previous post, since JFrame is Serializable, so the rmi call succeeded even if the server and client were on different JVMs. The newly created ClientImpl was serialized and sent across to the server JVM.
Ok, now for the null pointer exception.
From the stack trace, i can hardly make out anything since i dont have the line numbers in the code. However, the messageReceived() method does not have anything but a system.out and jtextArea1.append(). I am curious as to where jtextarea1 is defined/initialized. The only source of an NPE can be that jtextarea1 is null.(Assuming that fromUsername and message are not null)
Excuse me if i am missing out something related to swing in the above as swing is latin and greek to me
simranjit singh
Greenhorn

Joined: Mar 01, 2007
Posts: 12
jTextArea is defined / initialized when initcomponents() method in clientRMIImpl is called. i am developing my project in netbeans 5.5, jdk 1.6

initcomponents i guess you can see in the clientRMIImpl.java code in the code above..

what can i do to pass a reference of that window to this jtextArea when i get that reply from server?
System.out.print just above is working just fine.
 
GeeCON Prague 2014
 
subject: rmi callback