zt_bind()-related address bugfix, also dwr/LOGV refactor
This commit is contained in:
@@ -29,46 +29,63 @@ public class MainActivity extends AppCompatActivity {
|
||||
// Create ZeroTier socket
|
||||
int sock = zt.zt_socket(SDK.AF_INET, SDK.SOCK_STREAM, 0);
|
||||
|
||||
/*
|
||||
try {
|
||||
Thread.sleep(25000);
|
||||
}
|
||||
catch(java.lang.InterruptedException e) { }
|
||||
*/
|
||||
|
||||
int mode = 0; // client/server mode toggle
|
||||
// client/server mode toggle
|
||||
int mode = 1, err = -1;
|
||||
|
||||
// Establish outgoing connection
|
||||
if(mode==0)
|
||||
{
|
||||
int err = -1;
|
||||
while(err < 0) {
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch(java.lang.InterruptedException e) { }
|
||||
err = zt.zt_connect(sock, "10.9.9.100", 7003);
|
||||
err = zt.zt_connect(sock, "10.9.9.100", 7004);
|
||||
Log.d("TEST", "err = " + err + "\n");
|
||||
}
|
||||
|
||||
// TX
|
||||
zt.zt_write(sock, "Welcome to the machine".getBytes(), 16);
|
||||
|
||||
// RX
|
||||
byte[] buffer = new byte[12];
|
||||
zt.zt_read(sock, buffer, 12);
|
||||
String bufStr = new String(buffer);
|
||||
Log.d("TEST", "response = " + bufStr);
|
||||
// Test section
|
||||
for(int i=0; i<1000; i++)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
}
|
||||
catch(java.lang.InterruptedException e) { }
|
||||
|
||||
String msg = "Welcome to the machine!";
|
||||
int written = zt.zt_write(sock, msg.getBytes(), msg.length());
|
||||
Log.d("TEST", "TX[" + i + "] = " + written);
|
||||
|
||||
// RX
|
||||
byte[] buffer = new byte[1024];
|
||||
zt.zt_read(sock, buffer, buffer.length);
|
||||
String bufStr = new String(buffer);
|
||||
Log.d("TEST", "RX[" + i + "] = " + bufStr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Listen to incoming connections
|
||||
if(mode==1)
|
||||
{
|
||||
int err;
|
||||
zt.zt_bind(sock, "0.0.0.0", 8081);
|
||||
zt.zt_listen(sock,1);
|
||||
err = zt.zt_accept(sock,null); // Pass a ZTAddress to get remote host's address (if you want)
|
||||
while(err < 0) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch(java.lang.InterruptedException e) { }
|
||||
err = zt.zt_bind(sock, "0.0.0.0", 8080);
|
||||
Log.d("TEST", "err = " + err + "\n");
|
||||
}
|
||||
|
||||
|
||||
//zt.zt_listen(sock,1);
|
||||
//err = zt.zt_accept(sock,null); // Pass a ZTAddress to get remote host's address (if you want)
|
||||
|
||||
//Log.d("TEST", "accept_err = " + err);
|
||||
|
||||
// Example ZTAddress usage
|
||||
/*
|
||||
|
||||
56
integrations/nanomsg/pipeline.c
Normal file
56
integrations/nanomsg/pipeline.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <assert.h>
|
||||
#include <libc.h>
|
||||
#include <stdio.h>
|
||||
#include <nanomsg/nn.h>
|
||||
#include <nanomsg/pipeline.h>
|
||||
|
||||
// zerotier
|
||||
#include <SDK.h>
|
||||
#include <SDK_ServiceSetup.hpp>
|
||||
|
||||
#define NODE0 "node0"
|
||||
#define NODE1 "node1"
|
||||
|
||||
int node0 (const char *url)
|
||||
{
|
||||
int sock = nn_socket (AF_SP, NN_PULL);
|
||||
assert (sock >= 0);
|
||||
assert (nn_bind (sock, url) >= 0);
|
||||
while (1)
|
||||
{
|
||||
char *buf = NULL;
|
||||
int bytes = nn_recv (sock, &buf, NN_MSG, 0);
|
||||
assert (bytes >= 0);
|
||||
printf ("NODE0: RECEIVED \"%s\"\n", buf);
|
||||
nn_freemsg (buf);
|
||||
}
|
||||
}
|
||||
|
||||
int node1 (const char *url, const char *msg)
|
||||
{
|
||||
int sz_msg = strlen (msg) + 1; // '\0' too
|
||||
int sock = nn_socket (AF_SP, NN_PUSH);
|
||||
assert (sock >= 0);
|
||||
assert (nn_connect (sock, url) >= 0);
|
||||
printf ("NODE1: SENDING \"%s\"\n", msg);
|
||||
int bytes = nn_send (sock, msg, sz_msg, 0);
|
||||
assert (bytes == sz_msg);
|
||||
return nn_shutdown (sock, 0);
|
||||
}
|
||||
|
||||
int main (const int argc, const char **argv)
|
||||
{
|
||||
// start zerotier
|
||||
init_service(INTERCEPT_ENABLED, "/Users/Joseph/utest3");
|
||||
|
||||
if (strncmp (NODE0, argv[1], strlen (NODE0)) == 0 && argc > 1)
|
||||
return node0 (argv[2]);
|
||||
else if (strncmp (NODE1, argv[1], strlen (NODE1)) == 0 && argc > 2)
|
||||
return node1 (argv[2], argv[3]);
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "Usage: pipeline %s|%s <URL> <ARG> ...'\n",
|
||||
NODE0, NODE1);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user