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.
|
||||
*/
|
||||
|
||||
import com.zerotier.libzt.ZeroTier;
|
||||
import com.zerotier.libzt.ZeroTierEventListener;
|
||||
package com.zerotier.libzt.javasimpleexample;
|
||||
|
||||
public class ExampleApp
|
||||
{
|
||||
static void sleep(int ms)
|
||||
{
|
||||
try { Thread.sleep(ms); }
|
||||
catch (InterruptedException e) { e.printStackTrace(); }
|
||||
import com.zerotier.libzt.ZeroTier;
|
||||
|
||||
public class Main {
|
||||
|
||||
static void sleep(int ms) {
|
||||
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
|
||||
MyZeroTierEventListener listener = new MyZeroTierEventListener();
|
||||
int servicePort = 9994;
|
||||
@@ -54,13 +56,9 @@ public class ExampleApp
|
||||
/*
|
||||
|
||||
Begin using socket API after this point
|
||||
|
||||
Use ZeroTier.ZeroTierSocket, ZeroTier.ZeroTierSocketFactory, etc
|
||||
|
||||
(or)
|
||||
|
||||
ZeroTier.socket(), ZeroTier.connect(), etc
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.zerotier.libzt.javasimpleexample;
|
||||
|
||||
import com.zerotier.libzt.ZeroTier;
|
||||
import com.zerotier.libzt.ZeroTierEventListener;
|
||||
import com.zerotier.libzt.ZeroTierPeerDetails;
|
||||
|
||||
public class MyZeroTierEventListener implements ZeroTierEventListener {
|
||||
|
||||
public boolean isNetworkReady = 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) {
|
||||
System.out.println("EVENT_NODE_UP: nodeId=" + Long.toHexString(id));
|
||||
}
|
||||
Reference in New Issue
Block a user