Updated Android example
This commit is contained in:
@@ -18,6 +18,8 @@ import com.zerotier.libzt.ZeroTierSSLSocketFactory;
|
||||
import com.zerotier.libzt.ZeroTierSocketAddress;
|
||||
import com.zerotier.libzt.ZeroTierSocketOptionValue;
|
||||
import com.zerotier.libzt.ZeroTierSocketImplFactory;
|
||||
import com.zerotier.libzt.ZeroTierProtoStats;
|
||||
|
||||
// Custom ZeroTierEventListener
|
||||
import com.example.exampleandroidapp.MyZeroTierEventListener;
|
||||
|
||||
@@ -42,6 +44,30 @@ public class MainActivity extends AppCompatActivity {
|
||||
while (listener.isNetworkReady == false) { sleep (50); }
|
||||
|
||||
boolean testBackgroundWorkerGET = true;
|
||||
boolean testRestart = true;
|
||||
boolean testProtocolStats = true;
|
||||
|
||||
if (testRestart) {
|
||||
for (int i=0; i<10; i++) {
|
||||
System.out.println("restarting...");
|
||||
ZeroTier.restart();
|
||||
sleep(10000);
|
||||
}
|
||||
}
|
||||
|
||||
if (testProtocolStats) {
|
||||
ZeroTierProtoStats protocolSpecificStats = new ZeroTierProtoStats();
|
||||
int numPings = 0;
|
||||
System.out.println("recording stats...");
|
||||
while (true) {
|
||||
sleep(50);
|
||||
ZeroTier.get_protocol_stats(ZeroTier.STATS_PROTOCOL_ICMP, protocolSpecificStats);
|
||||
if (protocolSpecificStats.recv > numPings) {
|
||||
numPings = protocolSpecificStats.recv;
|
||||
System.out.println("icmp.recv="+numPings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (testBackgroundWorkerGET) {
|
||||
// Start worker threads (staggered by)
|
||||
|
||||
@@ -11,11 +11,12 @@ public class MyZeroTierEventListener implements ZeroTierEventListener {
|
||||
public void onZeroTierEvent(long id, int eventCode)
|
||||
{
|
||||
if (eventCode == ZeroTier.EVENT_NODE_UP) {
|
||||
System.out.println("EVENT_NODE_UP: nodeId=" + Long.toHexString(id));
|
||||
// Safe to ignore this callback
|
||||
//System.out.println("EVENT_NODE_UP");
|
||||
}
|
||||
if (eventCode == ZeroTier.EVENT_NODE_ONLINE) {
|
||||
// The core service is running properly and can join networks now
|
||||
System.out.println("EVENT_NODE_ONLINE: nodeId=" + Long.toHexString(ZeroTier.get_node_id()));
|
||||
System.out.println("EVENT_NODE_ONLINE: nodeId=" + Long.toHexString(id));
|
||||
isOnline = true;
|
||||
}
|
||||
if (eventCode == ZeroTier.EVENT_NODE_OFFLINE) {
|
||||
|
||||
Reference in New Issue
Block a user