Update documentation
This commit is contained in:
7
examples/c/README.md
Normal file
7
examples/c/README.md
Normal file
@@ -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
|
||||
=====
|
||||
|
||||
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
|
||||
# ZeroTier Sockets for C# .NET
|
||||
|
||||
Add `ZeroTier.Sockets` to your project:
|
||||
```powershell
|
||||
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:
|
||||
|
||||
```
|
||||
cp ../../lib/release/${YOUR_HOST_TUPLE}-pinvoke/libzt.* .
|
||||
```
|
||||
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.
|
||||
- Getting Started: [docs.zerotier.com/sockets](https://docs.zerotier.com/sockets/tutorial.html)
|
||||
- Source [src/bindings/csharp](../../src/bindings/csharp)
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
# 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)
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
# Python example
|
||||
|
||||
This example demonstrates how to use the ZeroTier socket interface provided by libzt in a Python application. The API is designed to be a drop-in replacement for the Python [Low-level networking interface](https://docs.python.org/3/library/socket.html).
|
||||
|
||||
Note: Only `AF_INET` and `AF_INET6` address families are supported.
|
||||
|
||||
### Install
|
||||
|
||||
```
|
||||
@@ -12,12 +8,12 @@ pip install libzt
|
||||
|
||||
### Run
|
||||
```
|
||||
python3 example.py server id-path/bob 0123456789abcdef 9997 8080
|
||||
python3 example.py client id-path/alice 0123456789abcdef 9996 11.22.33.44 8080
|
||||
python3 example.py server id-path/bob 0123456789abcdef 8080
|
||||
python3 example.py client id-path/alice 0123456789abcdef ip.ip.ip.ip 8080
|
||||
```
|
||||
|
||||
*Where `9996` and `9997` are arbitrary ports that you allow ZeroTier to use for encrypted UDP traffic, port `8080` is an arbitrary port used by the client/server socket code, and `11.22.33.44` should be whatever IP address the network assigns your node.*
|
||||
## Links
|
||||
|
||||
### Implementation Details
|
||||
|
||||
- See [src/bindings/python](../../src/bindings/python)
|
||||
- Getting Started: [docs.zerotier.com/sockets](https://docs.zerotier.com/sockets/tutorial.html)
|
||||
- Source [src/bindings/python](../../src/bindings/python)
|
||||
- Design inspired by: [Python Low-level networking interface](https://docs.python.org/3/library/socket.html)
|
||||
|
||||
Reference in New Issue
Block a user