api notes
This commit is contained in:
@@ -15,48 +15,6 @@ public class Demo : MonoBehaviour
|
||||
|
||||
int server_connection_socket; // The "connection id"
|
||||
|
||||
private void zt_sample_network_test_thread()
|
||||
{
|
||||
print("test_network");
|
||||
|
||||
byte error;
|
||||
// Prepare sample data buffer
|
||||
/*
|
||||
byte[] buffer = new byte[1024];
|
||||
Stream stream = new MemoryStream(buffer);
|
||||
BinaryFormatter f = new BinaryFormatter();
|
||||
f.Serialize ( stream , "Welcome to the machine! (from Unity3D)" );
|
||||
int error;
|
||||
*/
|
||||
|
||||
// Connect to server
|
||||
int connfd = zt.Connect (0, "172.22.211.245", 8888, out error);
|
||||
print(connfd);
|
||||
|
||||
// Send sample data to server
|
||||
//int bytes_written = zt.Send(connfd,buffer,0, out error);
|
||||
//print(bytes_written);
|
||||
|
||||
//char[] buffer = new char[1024];
|
||||
//buffer = "hello".ToCharArray();
|
||||
//print (buffer);
|
||||
//Stream stream = new MemoryStream(buffer);
|
||||
//BinaryFormatter formatter = new BinaryFormatter();
|
||||
//formatter.Serialize(stream, "HelloServer");
|
||||
//int bufferSize = 1024;
|
||||
|
||||
Debug.Log ("Sending...");
|
||||
int bytes_written = zt.Send(connfd, "hello".ToCharArray(),4, out error);
|
||||
print(bytes_written);
|
||||
}
|
||||
|
||||
public void zt_test_network()
|
||||
{
|
||||
Thread networkTestThread = new Thread(() => { zt_sample_network_test_thread();});
|
||||
networkTestThread.IsBackground = true;
|
||||
networkTestThread.Start();
|
||||
}
|
||||
|
||||
// Demo button methods
|
||||
public void Join()
|
||||
{
|
||||
|
||||
@@ -27,16 +27,16 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
|
||||
using System.IO;
|
||||
using C5;
|
||||
|
||||
public class ZeroTierNetworkInterface {
|
||||
|
||||
@@ -64,9 +64,6 @@ public class ZeroTierNetworkInterface {
|
||||
const string DLL_PATH = "ZeroTierSDK_Unity3D_ANDROID";
|
||||
#endif
|
||||
|
||||
// ZeroTier background thread
|
||||
private Thread ztThread;
|
||||
|
||||
// Interop structures
|
||||
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
|
||||
public struct sockaddr {
|
||||
@@ -77,6 +74,11 @@ public class ZeroTierNetworkInterface {
|
||||
public string sa_data;
|
||||
}
|
||||
|
||||
// ZeroTier background thread
|
||||
private Thread ztThread;
|
||||
|
||||
private ArrayList<int> connections = new ArrayList<int> ();
|
||||
|
||||
// Virtual network interace config
|
||||
private int MaxPacketSize;
|
||||
private string rpc_path = "/does/this/work";
|
||||
@@ -88,6 +90,7 @@ public class ZeroTierNetworkInterface {
|
||||
Debug.Log("Native ZT Plugin: " + str);
|
||||
}
|
||||
|
||||
#region
|
||||
// ZeroTier service / debug initialization
|
||||
[DllImport (DLL_PATH)]
|
||||
public static extern void SetDebugFunction( IntPtr fp );
|
||||
@@ -129,6 +132,7 @@ public class ZeroTierNetworkInterface {
|
||||
private static extern bool zt_join_network(string nwid);
|
||||
[DllImport (DLL_PATH)]
|
||||
private static extern void zt_leave_network(string nwid);
|
||||
#endregion
|
||||
|
||||
// Thread which starts the ZeroTier service
|
||||
// The ZeroTier service may spin off a SOCKS5 proxy server
|
||||
@@ -295,6 +299,10 @@ public class ZeroTierNetworkInterface {
|
||||
*/
|
||||
public NetworkEventType Receive(out int hostId, out int connectionId, out int channelId, byte[] buffer, int bufferSize, out int receivedSize, out byte error)
|
||||
{
|
||||
for (int i = 0; i < connections.Count; i++) {
|
||||
|
||||
}
|
||||
|
||||
int res;
|
||||
res = zt_recv (connectionId, buffer, bufferSize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user