25
examples/java/README.md
Normal file
25
examples/java/README.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
### How to compile/use this example:
|
||||||
|
|
||||||
|
1. Follow "Building from source" section from README.md in the root of this git repository
|
||||||
|
(the linking step/example from that section does not apply to this example)
|
||||||
|
|
||||||
|
2. Create the java library .jar file:
|
||||||
|
|
||||||
|
```
|
||||||
|
make host_jar_release
|
||||||
|
```
|
||||||
|
|
||||||
|
for other `host_jar` variants see Makefile in the root of this git repository
|
||||||
|
|
||||||
|
2. Copy the output .jar to this directory:
|
||||||
|
|
||||||
|
```
|
||||||
|
cp lib/lib/release/linux-x86_64/zt.jar examples/java/simpleExample/
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Now you can compile this example:
|
||||||
|
|
||||||
|
```
|
||||||
|
cd src
|
||||||
|
javac -cp ../zt.jar ./com/zerotier/libzt/javasimpleexample/*.java
|
||||||
|
```
|
||||||
@@ -24,19 +24,21 @@
|
|||||||
* of your own application.
|
* of your own application.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.zerotier.libzt.ZeroTier;
|
package com.zerotier.libzt.javasimpleexample;
|
||||||
import com.zerotier.libzt.ZeroTierEventListener;
|
|
||||||
|
|
||||||
public class ExampleApp
|
import com.zerotier.libzt.ZeroTier;
|
||||||
{
|
|
||||||
static void sleep(int ms)
|
public class Main {
|
||||||
{
|
|
||||||
try { Thread.sleep(ms); }
|
static void sleep(int ms) {
|
||||||
catch (InterruptedException e) { e.printStackTrace(); }
|
try {
|
||||||
|
Thread.sleep(ms);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
// Set up event listener and start service
|
// Set up event listener and start service
|
||||||
MyZeroTierEventListener listener = new MyZeroTierEventListener();
|
MyZeroTierEventListener listener = new MyZeroTierEventListener();
|
||||||
int servicePort = 9994;
|
int servicePort = 9994;
|
||||||
@@ -54,13 +56,9 @@ public class ExampleApp
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Begin using socket API after this point
|
Begin using socket API after this point
|
||||||
|
|
||||||
Use ZeroTier.ZeroTierSocket, ZeroTier.ZeroTierSocketFactory, etc
|
Use ZeroTier.ZeroTierSocket, ZeroTier.ZeroTierSocketFactory, etc
|
||||||
|
|
||||||
(or)
|
(or)
|
||||||
|
|
||||||
ZeroTier.socket(), ZeroTier.connect(), etc
|
ZeroTier.socket(), ZeroTier.connect(), etc
|
||||||
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
|
package com.zerotier.libzt.javasimpleexample;
|
||||||
|
|
||||||
import com.zerotier.libzt.ZeroTier;
|
import com.zerotier.libzt.ZeroTier;
|
||||||
import com.zerotier.libzt.ZeroTierEventListener;
|
import com.zerotier.libzt.ZeroTierEventListener;
|
||||||
import com.zerotier.libzt.ZeroTierPeerDetails;
|
|
||||||
|
|
||||||
public class MyZeroTierEventListener implements ZeroTierEventListener {
|
public class MyZeroTierEventListener implements ZeroTierEventListener {
|
||||||
|
|
||||||
public boolean isNetworkReady = false;
|
public boolean isNetworkReady = false;
|
||||||
public boolean isOnline = false;
|
public boolean isOnline = false;
|
||||||
|
|
||||||
public void onZeroTierEvent(long id, int eventCode)
|
public void onZeroTierEvent(long id, int eventCode) {
|
||||||
{
|
|
||||||
if (eventCode == ZeroTier.EVENT_NODE_UP) {
|
if (eventCode == ZeroTier.EVENT_NODE_UP) {
|
||||||
System.out.println("EVENT_NODE_UP: nodeId=" + Long.toHexString(id));
|
System.out.println("EVENT_NODE_UP: nodeId=" + Long.toHexString(id));
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user