OrangeCabinet 0.2.2
dotnet add package OrangeCabinet --version 0.2.2
NuGet\Install-Package OrangeCabinet -Version 0.2.2
<PackageReference Include="OrangeCabinet" Version="0.2.2" />
paket add OrangeCabinet --version 0.2.2
#r "nuget: OrangeCabinet, 0.2.2"
// Install OrangeCabinet as a Cake Addin #addin nuget:?package=OrangeCabinet&version=0.2.2 // Install OrangeCabinet as a Cake Tool #tool nuget:?package=OrangeCabinet&version=0.2.2
OrangeCabinet - C# .NET async udp server & client
feature
OrangeCabinet is 'Asynchronous Programming Model (APM)' socket wrapper library,
with 'Task-based Asynchronous Pattern (TAP)' at callback methods.
Otherwise, APM and TAP mixed.
Sync methods (Incoming, Timeout and Shutdown) are disallowed for async override.
If you want to use 'async',
Async methods (IncomingAsync, TimeoutAsync and ShutdownAsync) are override with 'UseAsyncCallback = true'.
- Callback is below.
- 'Incoming or IncomingAsync' (received)
- 'Timeout or TimeoutAsync' (timeout)
- 'Shutdown or ShutdownAsync' (shutdown)
- Can store user value in remote.
- Check timeout at regular intervals by last receive time.
- Client bind too, not connect. So, previously known client port.
(notice)
Synchronous methods are now obsolete.
Please change to asynchronous methods.
how to use
callback (sync)
public class Callback : OcCallback
{
private const string Key = "inc";
public override void Incoming(OcRemote remote, byte[] message)
{
Console.WriteLine($"Received: {Encoding.UTF8.GetString(message)} ({remote})");
int inc = remote.GetValue<int>(Key);
inc++;
remote.SetValue(Key, inc);
remote.Send($"{inc}");
if (inc > 10)
{
remote.ClearValue(Key);
remote.Escape();
}
}
public override void Timeout(OcRemote remote)
{
Console.WriteLine($"Timeout: {remote}");
}
public override void Shutdown(OcRemote remote)
{
Console.WriteLine($"Shutdown: {remote}");
}
}
callback (async)
public class AsyncCallback : OcCallback
{
private const string Key = "inc";
public override bool UseAsyncCallback { get; init; } = true;
public override async Task IncomingAsync(OcRemote remote, byte[] message)
{
Console.WriteLine($"Received: {Encoding.UTF8.GetString(message)} ({remote})");
int inc = remote.GetValue<int>(Key);
inc++;
remote.SetValue(Key, inc);
await remote.SendAsync($"{inc}");
if (inc > 10)
{
remote.ClearValue(Key);
remote.Escape();
}
}
public override Task TimeoutAsync(OcRemote remote)
{
Console.WriteLine($"Timeout: {remote}");
return Task.CompletedTask;
}
public override Task ShutdownAsync(OcRemote remote)
{
Console.WriteLine($"Shutdown: {remote}");
return Task.CompletedTask;
}
}
for server (ip v4)
public static void Main(string[] args)
{
var serverBinder = new OcBinder(new SampleCallback())
{
BindPort = 8710,
};
var server = new OcLocal(serverBinder);
server.Start();
server.SendTo("0", new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8710)); // Send from server to some endpoint what you hope.
server.WaitFor();
// ...
server.Shutdown();
}
for client (ip v4)
public static void Main(string[] args)
{
using var clientBinder = new OcBinder(new Callback())
{
BindPort = 18710,
};
var client = new OcRemote(clientBinder, "127.0.0.1", 8710);
for (int j = 0; j < 3; j++)
{
client.Send($"{j}");
}
}
for server (ip v6)
public static void Main(string[] args)
{
var serverBinder = new OcBinder(new SampleCallback())
{
SocketAddressFamily = OcSocketAddressFamily.Ipv6,
BindPort = 8710,
};
var server = new OcLocal(serverBinder);
server.Start();
server.SendTo("0", new IPEndPoint(IPAddress.Parse("::1"), 8710)); // Send from server to some endpoint what you hope.
server.WaitFor();
// ...
server.Shutdown();
}
for client (ip v6)
public static void Main(string[] args)
{
using var clientBinder = new OcBinder(new Callback())
{
SocketAddressFamily = OcSocketAddressFamily.Ipv6,
BindPort = 18710,
};
var client = new OcRemote(clientBinder, "::1", 8710);
for (int j = 0; j < 3; j++)
{
client.Send($"{j}");
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on OrangeCabinet:
Package | Downloads |
---|---|
FluentNetting
Fluent forwarded server. |
GitHub repositories
This package is not used by any popular GitHub repositories.