{"id":27438342,"url":"https://github.com/comidan/heartbeatprotocol","last_synced_at":"2025-04-14T20:35:16.751Z","repository":{"id":55517819,"uuid":"142049922","full_name":"comidan/HeartbeatProtocol","owner":"comidan","description":"Heartbeat protocol written in Java, working over UDP","archived":false,"fork":false,"pushed_at":"2020-12-27T15:19:00.000Z","size":28,"stargazers_count":13,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-02-28T14:12:42.887Z","etag":null,"topics":["heartbeat-protocol","java","network","udp"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/comidan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-23T17:56:43.000Z","updated_at":"2022-06-01T19:24:34.000Z","dependencies_parsed_at":"2022-08-15T02:10:58.115Z","dependency_job_id":null,"html_url":"https://github.com/comidan/HeartbeatProtocol","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comidan%2FHeartbeatProtocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comidan%2FHeartbeatProtocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comidan%2FHeartbeatProtocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comidan%2FHeartbeatProtocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/comidan","download_url":"https://codeload.github.com/comidan/HeartbeatProtocol/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248956957,"owners_count":21189458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["heartbeat-protocol","java","network","udp"],"created_at":"2025-04-14T20:35:16.053Z","updated_at":"2025-04-14T20:35:16.737Z","avatar_url":"https://github.com/comidan.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Maintainability](https://api.codeclimate.com/v1/badges/1653a270f84252f44179/maintainability)](https://codeclimate.com/github/Daniele-Comi/HeartbeatProtocol/maintainability) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/954a0d9afcda4fa08e90bd5de0336b8e)](https://app.codacy.com/app/Daniele-Comi/HeartbeatProtocol?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=Daniele-Comi/HeartbeatProtocol\u0026utm_campaign=Badge_Grade_Settings)\n\n# HeartbeatProtocol\nHeartbeat protocol written in Java, working over UDP\n\n### UML Class Diagram\n[![N|UML](https://image.ibb.co/fDiJ0f/Heartbeat-Protocol-UML.png)](https://image.ibb.co/fDiJ0f/Heartbeat-Protocol-UML.png)\n\n\n# Powered by \n  [![N|Java 8](http://www.winpenpack.com/en/e107_files/downloadthumbs/java_logo.png)](http://www.oracle.com/technetwork/java/index.html)\n# Testing tools \n[![N|Sonarqube](https://university.itametis.com/website/files/images/logos/sonarqube.png)](https://www.sonarqube.org)[![N|Travis CI](https://ih1.redbubble.net/image.854734222.3175/flat,128x128,075,f-pad,128x128,f8f8f8.u2.jpg)](https://travis-ci.com) [![N|Maven](https://www.myget.org/Content/images/packageDefaultIcon_maven.png)](http://maven.apache.org/download.cgi) [![N|JUnit](https://res.cloudinary.com/codetrace/raw/upload/v1518632546/java:junit:junit.png)](https://junit.org/junit5/) [![N|Code Climate](https://images.ctfassets.net/3ouphkrynjol/3dbUrGMAFOuYQasYGWM0SK/f7167126b1ff3e8cc7c895e508c08a13/codeclimate.com.png)](https://codeclimate.com)\n\n### Heartbeat Protocol Description\nThe heartbeat protocol is structured on a continuous notification of a UDP datagram with a delay of 1000 milliseconds. The payload field contains the identifier ID from the client that can consist of a string such as the MAC address of the network cards in current use by the ping source or an identifier such as a username.\nThe server will listen to the various ping sorting them according to the identifier and managing the various states that they will define themselves.\nWhenever the server will notice that after a delay of 3000 milliseconds has not received any ping from the client will notify through an event the user of this protocol of the\nprobable loss of connection advising to limit or stop the exchange of data through any other connection-dependent protocol such as TCP.\nIf within 5,000 milliseconds you will receive with this identifier the client will be connected again, meaning that it is possible to restore the data communication channel.\nOtherwise the client will be considered completely offline.\nAll this will be notified as mentioned above through an event management as shown below:\n \n```java\n@Override\npublic void onHeartbeat(HeartbeatEvent event) {\n    LOGGER.log(Level.INFO, () -\u003e \"Received heartbeat from \" + event.getSource() + \" in \" + event.getTimeFromPreviousBeat() + \" at \" + event.getBeatTimeStamp());\n}\n\n@Override\npublic void onDeath(HeartbeatEvent event) {\n    LOGGER.log(Level.INFO, () -\u003e event.getSource() + \" died after \" + event.getTimeFromPreviousBeat() + \" at \" + event.getBeatTimeStamp());\n}\n\n@Override\npublic void onLossCommunication(HeartbeatEvent event) {\n    LOGGER.log(Level.INFO, () -\u003e \"Communication lost of \" + event.getSource() + \" in \" + event.getTimeFromPreviousBeat() + \" at \" + event.getBeatTimeStamp());\n}\n\n@Override\npublic void onReacquiredCommunication(HeartbeatEvent event) {\n    LOGGER.log(Level.INFO, () -\u003e \"Communication reacquired of \" + event.getSource() + \" in \" + event.getTimeFromPreviousBeat() + \" at \" + event.getBeatTimeStamp());\n}\n\n@Override\npublic void onAcquiredCommunication(HeartbeatEvent event) {\n    LOGGER.log(Level.INFO, () -\u003e event.getSource() + \" connected at \" + event.getBeatTimeStamp());\n}\n```\n     \nThe sample code above shows the capture of various events on the states of a client, it will then be the task of those who implement the listener the decision on what to do when capturing a certain type of event as below :\n```java\npublic class ServerStart implements HeartbeatListener {\n   private static final ServerStart thisInstance = new ServerStart();\n   \n   public static void main(String[] args) {\n        HeartbeatProtocolManager heartbeatProtocolManager = new HeartbeatProtocolManager(thisInstance);\n        heartbeatProtocolManager.addHost(\"Test\", 43210); //identifier, port\n        heartbeatProtocolManager.addHost(\"Test1\", 43211);\n   }\n        \n   @Override\n   public void onHeartbeat(HeartbeatEvent event) {\n       LOGGER.log(Level.INFO, () -\u003e \"Received heartbeat from \" + event.getSource() + \" in \" + event.getTimeFromPreviousBeat() + \" at \" + event.getBeatTimeStamp());\n   }\n\n   @Override\n   public void onDeath(HeartbeatEvent event) {\n       LOGGER.log(Level.INFO, () -\u003e event.getSource() + \" died after \" + event.getTimeFromPreviousBeat() + \" at \" + event.getBeatTimeStamp());\n   }\n\n   @Override\n   public void onLossCommunication(HeartbeatEvent event) {\n       LOGGER.log(Level.INFO, () -\u003e \"Communication lost of \" + event.getSource() + \" in \" + event.getTimeFromPreviousBeat() + \" at \" + event.getBeatTimeStamp());\n   }\n\n   @Override\n   public void onReacquiredCommunication(HeartbeatEvent event) {\n       LOGGER.log(Level.INFO, () -\u003e \"Communication reacquired of \" + event.getSource() + \" in \" + event.getTimeFromPreviousBeat() + \" at \" + event.getBeatTimeStamp());\n   }\n\n   @Override\n   public void onAcquiredCommunication(HeartbeatEvent event) {\n       LOGGER.log(Level.INFO, () -\u003e event.getSource() + \" connected at \" + event.getBeatTimeStamp());\n   }\n}\n```\n  \n  \nThe event generated in addition to containing the payload will also contain the delay passed with respect to the previous one with its own payload identifier and the timestamp of the current reception of the ping.\n  \nThe use of this protocol will allow a better management of the status of the connections between client and server and a greater control of the possible errors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomidan%2Fheartbeatprotocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomidan%2Fheartbeatprotocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomidan%2Fheartbeatprotocol/lists"}