Solved

RMI chat app

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split string containing \r\n in Java 46 44
more than one jdk and one jre 1 41
Desingning Refactoring existing code 2 24
Which non-HTML GUI front end to use with Java? 3 22
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

777 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