Solved

RMI chat app

Posted on 2000-04-20
5
716 Views
Last Modified: 2012-08-13
Currently I am trying to write a chat application using RMI and JDK1.2.  Since I am using jdk1.2 no Skeleton is required.  Anyway I have created the server which has an interface for the client consisting of 3 methods.  AddClient, which the client calls and passes itself in to register with the server.  The Server then adds the reference to a vector of all the clients that are registered.

PostMessage which a client calls passing in the Message that the server is supposed to distribute to other clients.

And unregister which the client calls to unregister with the server.

Anyway, the problem I am running into is that when the client calls register on the server and passes itself to the server, the client will get serialized and the server will then receive a copy of the client instead of a reference.  If I want the server to get a reference should I also create a stub for the client and have it register with the registry or can I use Remote?  I thought I tried remote once and it still seemed to give the server a copy of the client instead of the reference.  I can't use a copy cause when the server calls a method on the client it just executes on the server machine.

Also how can I override equals in client?  Since remote methods must throw RemoteException which equals does not in Object.  I need to override equals cause I am storing clients in a vector and when I add a new client to a vector I would like to make sure it does not exist...ie vector.get(client).equals(newClient).


Thanks
0
Comment
Question by:mvoiers
  • 4
5 Comments
 
LVL 3

Expert Comment

by:falter
ID: 2736681
Hi mvoiers ,

first part of your question sounds like you need something like a callback, which allows the server to call a method executed at the clients JVM.

I'm not familiar with RMI in JDK1.2, because all the stuff I have done was based on JDK1.1.x . As I know the RMI Interfaces have changed from 1.1 to 1.2.

Never the less I have written a RemoteObject (with JDK1.1.x) which is something like a callback for the RMI-Server.

I created this Object as a subclass of UnicastRemoteObject and send this Object
through a RMI-Method of a server object to the Server application.
After this was done the server is able to call a remote method executed at the client.

This solution (callback pattern) has one big disadvantage, you cannot use it across firewalls, because normally a firewall didn't allow incoming connections, what will be done by calling a remote method of a client remote object.

To solve this problem it may be easier do have a seperate thread in the client which is calling a method lets say "getNewMessage" and block this method on server side until a new method arrives or the RMI call terminates /timeout or some other reasons)


Please explain your second part "equals" a little bit more specific.
Do you mean you want avoid a client to register twice?

Why don't you try to have some more classes instead of one class "client"?

May be something like client this realy your client and something like ClientRef which is the Reference Object of a client at the Server.
Now it will be up to you to fill this ClientRef Object with Informations about your Client and also to write a method ClientRef.equals based on the attributes of ClientRef.



May be this helps a little bit
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2738557
http://www.google.com/search?q=RMI+CALLBAcks&lc=www&btnG=Google+Search

will give a lot of links and it will definitely solve Your problem..

I will add some sorted list of links in next comment
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2738558
http://www.google.com/search?q=RMI+CALLBAcks&lc=www&btnG=Google+Search

will give a lot of links and it will definitely solve Your problem..

I will add some sorted list of links in next comment
0
 
LVL 7

Accepted Solution

by:
Ravindra76 earned 150 total points
ID: 2738560
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2738568
Ok. I thinl this link is perfect solution

http://edocs.bea.com/wle/rmi/callbak.htm
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now