20 August 2013

Chat using the Remote Method Invocation (RMI) in Java


Hi Friends,

  I hope we all are aware with RMI (Remote Method Invocation).  In simple RMI is very powerful concept by Java, by which we can invoke the method of class residing on another machine.

 Just think we have a class A on machine M1, and we want to invoke the method of class A from our machine which is connected to machine M1 by any medium.  Java provide the feature to perform this task.

We can design our chat server using the RMI.  We have a server and several clients. In general in a chat room clients call or invoke a method of server or any how pass the message to server and then server re-transmit the message to particular client.

We can design chat application using the RMI.  You can download executable jar file from here.
First you need to run the Server jar file and click the button to start the server. Once the server started you can run the client. if you run the client on the same machine where you started the server, pass the server name localhost only, and then provide your nick name and you are logged in to chat server.  You can start multiple clients to test it.  There is no need to start the server again and again for each client. only on server will handle all the clients requests.

1.  Run the Server

 


2.  Once the server started run the client


          because server and client running on the same machine you can use the 'localhost' else
          you have to provide the machine name or IP address (priority) and after clicking the OK
          button provide you nick name.




3.  To test the chat server you can start the multiple clients let start one more client with nick
     name 'Gaurav' for this client also we will use the same server name 'localhost' or other
     machine name (or IP).



4.  Once you are done with this you can see the two user in online user box.


if you need any suggestion or help, feel free to contact me.. :)

You can download executable jar file from here.

You can download the source code also from here.. 

Happy Coding.. :) Happy Java.. :)


No comments:

Post a Comment