• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Chat Room Implementation with Java RMI

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am trying to design a very basic chat room in Java RMI. My design brief is that all clients messages should be displayed to other clients and also captured and displayed on the server. I have been able to get as far as getting all client messages to display on the server side, but I am having difficulty in being able to display the messages sent by clients to other clients. I have constructed a GUI for clients in netbeans for them to type and receive text. Does anyone know of any ways I can go about solving this issue?

Initially I thought that I could register all the clients into an array and then loop through that array when a message is received on the server from a client and send the message to all other clients. Im not sure what unique identifier i could use in this instance, the only thing that came to mind would be to capture the clients ip address and store this in an array and then create an interface class for the client program and then create a method that can be called form the server by looping through the IP addresses but surely this would require starting the rmiregistry service on the clients which is totally defeats the purpose of the application.

I have attached the code that I have so far for everything. I know my naming conventions are quite poor, so ill try and clarify as i post it. Any help will be greatly appreciated.

The Server Interface



The Server Side Code



Client GUI and Client Running Code

 
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Welcome to JavaRanch!!

You have to use NotifierObject(just a name) which extends UnicastRemoteObject.
the rmi theory is the same.

when server got a message
server checks stored IP arraylist and invokes each broadcast method.
(Yes that means then main server is a client and clients are the servers).
 
Lakshan Dissanayake
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Common - both server and client needs this class

Server Side - Only Server needs these two class RemoteObject, ServerMainClass


Client Side - Only Client needs these two class ServerConnector, ClientMainClass



You may implement the programme as you wish.

First run ServerMainClass
Then run ClientMainClass.

You will get following on Client console
"Successfully Invoked Method1"

You will get following on Server console
"Successfully Invoked Method3"
"Successfully Invoked Method2"

Hope this will help
Thanks!
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic