Solved

RMI chat app

Posted on 2000-04-20
5
719 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Way to decrease size of apk file 9 88
login jsp example 24 69
how to install java on RHEL image on EC2 4 42
servlet and mdb, jms error 1 39
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

820 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