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
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.
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.
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..
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)
Joined: Mar 01, 2007
used this.. again the null pointer exception.. i cannot figure out where i am going wrong..
this jtextArea is giving error
problem of getting that message on server window has been solved.. thanks alot.. will be glad if this nullpointer can also be removed..
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
Joined: Mar 01, 2007
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.