Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class myTimerTask extends TimerTask {
- private Connection con;
- public myTimerTask(Connection con) {
- this.con = con;
- }
- public void run()
- {
- this.con.sendHeartbeat();
- }
- public Connection getCon() {
- return con;
- }
- public void setCon(Connection con) {
- this.con = con;
- }
- }
- class Connection {
- private int type;
- private Timer connectionTimer;
- private Socket sock;
- //... Constructor
- public void activateConnection (int connectionType) {
- this.type = connectionType;
- this.connectionTimer.schedule(new myTimerTask(this), 60);
- }
- public void sendHeartbeat() {
- switch (type) {
- case 0: socket.sendSignOfLife(1); break;
- case 1: socket.sendSignOfLife(2); break;
- case 2: socket.sendSignOfLife(3); break;
- default: socket.sendSignOfLife(0);
- }
- }
- //... Getters & Setters
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement