- I am working on a Spring-MVC application and in that I would like to maintain a list of Online users, and also give the users a choice to put custom status like Online, Away, Do not Disturb, Invisible.
- The idea I had was to log in the userId,username, Ipaddress and save it in database as soon as user logs in(Method called at page after login). Now as I have the list of users who are online with their IP-Address, my intention was to ping these IP address every 5 minutes and see if user is alive and online. I was planning to use Springs @Scheduled methods.
- Do you guys think this will fan out and work as expected. I was thinking of clients who are behind router and all. If there is any optimal method to see who is online, and maintain their status even when they don't log out, but just close the browser(So the ping can detect it), I would like to know.
This is what I have till now :
@Scheduled(fixedRate=5000000)
public void demoServiceMethod () {
List<OnlineUsers> onlineUsersList = this.onlineUsersDAO.getOnlineUsers();
for(OnlineUsers onlineUsers : onlineUsersList) {
inet = InetAddress.getByAddress(address.toByteArray());
System.out.println("Sending Ping Request to " + inet);
System.out.println(inet.isReachable(5000) ? "Host is reachable" : "Host is NOT reachable");
// set online status depending upon output of inet.isReachable(5000)
}
}
Will this work, My project is complicated to integrate it without knowing if this is even good. Any help and other ideas would be nice. Thanks a lot. :-)
Aucun commentaire:
Enregistrer un commentaire