[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

RMI chat app

Posted on 2000-04-20
5
Medium Priority
?
734 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 450 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

649 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