Back to project page ConnectedSpace.
The source code is released under:
Copyright (c) 2015, Shreyas Raman <skraman1999@gmail.com>.
If you think the Android project ConnectedSpace listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package me.shreyasr.connected.android.networking; /*w w w . j a v a2 s .c om*/ import android.util.Log; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.SocketException; import java.util.TimerTask; class HeartbeatThread extends TimerTask { private final LobbyManager manager; private DatagramSocket sendSocket; public HeartbeatThread(LobbyManager manager) { this.manager = manager; Log.d("BROADCAST", "Creating Heartbeat Task"); try { sendSocket = new DatagramSocket(); sendSocket.setBroadcast(true); } catch (SocketException e) { e.printStackTrace(); } } @Override public void run() { DatagramPacket packet = new DatagramPacket(PacketManager.createHeartbeat(manager.currentStatus.ordinal()), 8, manager.broadcastAddress, 4242); try { sendSocket.send(packet); } catch (IOException e) { e.printStackTrace(); } } }