aspose file tools*
The moose likes Distributed Java and the fly likes how to detect when server gets down and connect to second server with RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "how to detect when server gets down and connect to second server with RMI" Watch "how to detect when server gets down and connect to second server with RMI" New topic
Author

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

A Alabdullah
Greenhorn

Joined: Apr 19, 2014
Posts: 1
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

Joined: Mar 24, 2008
Posts: 3832

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.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

Jmx notification should fullfill your need. It would let the client know (via rmi) when one server goes down.


Regards
Salil Verma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to detect when server gets down and connect to second server with RMI