Solved

RMI chat app

Posted on 2000-04-20
5
723 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
add projects t working set in maven 2 64
ejb message driven bean mdb creation steps 2 50
Netbeans and org.apache.commons.lang3 issue 3 52
Java import explained 4 46
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

738 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