4 changed files with 27 additions and 71 deletions
@ -0,0 +1,7 @@ |
|||||||
|
# libzt C API usage examples |
||||||
|
|
||||||
|
## Links |
||||||
|
|
||||||
|
- Getting Started: [docs.zerotier.com/sockets](https://docs.zerotier.com/sockets/tutorial.html) |
||||||
|
- C API [Reference docs](https://docs.zerotier.com/autogen/libzt/files/_zero_tier_sockets_8h) |
||||||
|
- C API [Header](../../include/ZeroTierSockets.h) |
||||||
@ -1,64 +1,11 @@ |
|||||||
ZeroTier Sockets for C# .NET |
# ZeroTier Sockets for C# .NET |
||||||
===== |
|
||||||
|
|
||||||
A replacement for the [System.Net.Sockets.Socket](https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket) class built atop ZeroTier's SDK using P/INVOKE. It is designed to be a direct drop-in replacement. The library consists of three main objects: `ZeroTier.Node`, `ZeroTier.Event`, and `ZeroTier.Socket`. No code change is required in your application beyond a small snippet of startup code, renaming `Socket` to `ZeroTier.Socket` (where applicable) and handling a smattering of events. |
|
||||||
|
|
||||||
# Overview |
|
||||||
|
|
||||||
Add `ZeroTier.Sockets` to your project: |
Add `ZeroTier.Sockets` to your project: |
||||||
```powershell |
```powershell |
||||||
Install-Package ZeroTier.Sockets |
Install-Package ZeroTier.Sockets |
||||||
``` |
``` |
||||||
|
|
||||||
See [example.cs](./example.cs) for complete client/server app implementation. |
## Links |
||||||
|
|
||||||
```csharp |
|
||||||
using System.Net.Sockets; |
|
||||||
using ZeroTier; |
|
||||||
|
|
||||||
void OnZeroTierEvent(ZeroTier.Event e) |
|
||||||
{ |
|
||||||
Console.WriteLine("{0} ({1})", e.EventCode, e.EventName); |
|
||||||
} |
|
||||||
... |
|
||||||
|
|
||||||
ZeroTier.Node node = new ZeroTier.Node("path", OnZeroTierEvent, 9991); |
|
||||||
|
|
||||||
node.Start(); |
|
||||||
node.Join(0xc287ac0b42a6fb4c); |
|
||||||
|
|
||||||
... |
|
||||||
|
|
||||||
ZeroTier.Socket sock = new ZeroTier.Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp); |
|
||||||
|
|
||||||
sock.Connect(remoteEndPoint); |
|
||||||
|
|
||||||
... |
|
||||||
|
|
||||||
node.Stop(); |
|
||||||
``` |
|
||||||
|
|
||||||
# Building example without NuGet package (Advanced) |
|
||||||
|
|
||||||
From top-level repo directory, build `libzt.dll/so/dylib`: |
|
||||||
|
|
||||||
```bash |
|
||||||
make host_pinvoke_release |
|
||||||
``` |
|
||||||
|
|
||||||
Copy `libzt.dll/so/dylib` into this project directory: |
|
||||||
|
|
||||||
``` |
- Getting Started: [docs.zerotier.com/sockets](https://docs.zerotier.com/sockets/tutorial.html) |
||||||
cp ../../lib/release/${YOUR_HOST_TUPLE}-pinvoke/libzt.* . |
- Source [src/bindings/csharp](../../src/bindings/csharp) |
||||||
``` |
|
||||||
Where `${YOUR_HOST_TUPLE}` is something like: `linux-x86_64`, `macOS-x86_64`, etc. |
|
||||||
|
|
||||||
Build language binding layer, `ZeroTier.Sockets.dll`: |
|
||||||
|
|
||||||
```bash |
|
||||||
cd examples/csharp |
|
||||||
${CSHARP_COMPILER} -target:library -out:ZeroTier.Sockets.dll ../../src/bindings/csharp/*.cs |
|
||||||
${CSHARP_COMPILER} -reference:ZeroTier.Sockets.dll example.cs |
|
||||||
./example.exe |
|
||||||
``` |
|
||||||
Where `${CSHARP_COMPILER}` may be `csc` or `mono-csc` depending on your platform. |
|
||||||
|
|||||||
@ -1,9 +1,15 @@ |
|||||||
# Java example |
# Java example |
||||||
|
|
||||||
1). Build or download the `libzt-1.3.3.jar`, copy it to this directory |
Build or download the `libzt-${VERSION}.jar`, and copy it to this directory. |
||||||
|
|
||||||
2). Run `make` |
``` |
||||||
|
make |
||||||
|
java -cp ".:libzt-${VERSION}.jar" Example server id_path 0123456789abcdef 9997 |
||||||
|
java -cp ".:libzt-${VERSION}.jar" Example client id_path 0123456789abcdef ip.ip.ip.ip 9997 |
||||||
|
``` |
||||||
|
|
||||||
3). `java -cp ".:libzt-1.3.3.jar" Example id_path 0123456789abcdef 9997` |
## Links |
||||||
|
|
||||||
See [src/bindings/java](../../src/bindings/java) for wrapper implementation code. |
- Getting Started: [docs.zerotier.com/sockets](https://docs.zerotier.com/sockets/tutorial.html) |
||||||
|
- Java API: [docs.zerotier.com/sockets-java](https://docs.zerotier.com/sockets-java/) |
||||||
|
- Source [src/bindings/java](../../src/bindings/java) |
||||||
|
|||||||
Loading…
Reference in new issue