*
The moose likes Distributed Java and the fly likes Chat Room Implementation with Java RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Chat Room Implementation with Java RMI" Watch "Chat Room Implementation with Java RMI" New topic
Author

Chat Room Implementation with Java RMI

Jethro Reid
Greenhorn

Joined: Dec 18, 2013
Posts: 1
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

Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 132

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).


Are you better than me? Then please show me my mistakes..
Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 132

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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Chat Room Implementation with Java RMI
 
Similar Threads
Text from txtfield in txt file and from file to combobox
java programming
Pressing a button to open a new window
iperf
JTextField is not working for setText()