Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to detect when server gets down and connect to second server with RMI

 
A Alabdullah
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to detect when server gets down!


I'm creating simple TCP server/client chat, when a client sends a text
the server receives it and sends it to all connected clients

I want to create redundant server, when one server gets down, clients should connect to the
second server automatically,
how to use RMI to achieve this! I want the client side detects when the server is down at any time and directly connect to the other one


This is what I have currently:


server side:
first class:
accepts new socket from client and add it to arrayList of sockets
create object of ClientThread that implements thread, and pass the socket to it



second class:
Extends Thread and has run() method which receives text from one client and loop through the ArrayList of
sockets that created in first class and send to all connected sockets.
the ArrayList in first class is public and I access it like:



Client side:
has only one class that extends JFrame and implements AcionListener,
- it has a method that create sockets to server,and read any thing comes from server
- sending text to server is in actionPerform of Send button
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Alabdullah wrote:...
I want to create redundant server, when one server gets down, clients should connect to the
second server automatically,...

Typically in enterprise this would be achieved with HA/LB as the requests will be routed to any other server via LB at the server side.
...how to use RMI to achieve this! I want the client side detects when the server is down at any time and directly connect to the other one...

This would add additional overhead at the client side on the other hand. But if you need it you would have to check for heartbeat of the set of defined servers and route requests accordingly at the client side.

 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jmx notification should fullfill your need. It would let the client know (via rmi) when one server goes down.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic