Flare.Tcp
0.2.3
dotnet add package Flare.Tcp --version 0.2.3
NuGet\Install-Package Flare.Tcp -Version 0.2.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Flare.Tcp" Version="0.2.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Flare.Tcp --version 0.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Flare.Tcp, 0.2.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Flare.Tcp as a Cake Addin #addin nuget:?package=Flare.Tcp&version=0.2.3 // Install Flare.Tcp as a Cake Tool #tool nuget:?package=Flare.Tcp&version=0.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Flare.Tcp
A basic multi-client message-based tcp server (and client).
Using the FlareTcpServer
// create a new server and start listening on port 4242
using var server = new FlareTcpServer();
server.Start(4242);
// accept a client and send the string "Test"
using var client = await server.AcceptClientAsync();
await client.WriteMessageAsync(Encoding.UTF8.GetBytes("You connected successfully!"));
// read the response and print it
using var message = await client.ReadNextMessageAsync();
Console.WriteLine(Encoding.UTF8.GetString(message.Span));
// stop listening.
server.Shutdown();
Using the FlareTcpClient
// create a new client and connect to localhost on port 4242
using var client = new FlareTcpClient();
await client.ConnectAsync(IPAddress.Loopback, 4242);
// send "Test" to the server and print the response
await client.WriteMessageAsync(Encoding.UTF8.GetBytes("Knock knock"));
using var message = await client.ReadNextMessageAsync();
Console.WriteLine(Encoding.UTF8.GetString(message.Span));
// disconnect from the server
client.Disconnect();
Using the ConcurrentFlareTcpServer
// create a new server
using var server = new ConcurrentFlareTcpServer();
// attach event handlers
server.ClientConnected += clientId => {
Console.WriteLine($"Client {clientId} connected.");
};
server.ClientDisconnected += clientId => {
Console.WriteLine($"Client {clientId} disconnected.");
// stop the server
server.Shutdown();
};
server.MessageReceived += (clientId, message) => {
// echo message back to client and wait for it to be sent.
server.EnqueueMessage(clientId, message);
};
// start listening on port 4242.
await server.ListenAsync(4242);
Using the ConcurrentFlareTcpClient
// create a new client
using var client = new ConcurrentFlareTcpClient();
// attach message callback
client.MessageReceived += message => {
// print message to console
Console.WriteLine(Encoding.UTF8.GetString(message.Span));
// free the message buffer
message.Dispose();
// disconnect from server
client.Disconnect();
};
// connect to localhost on port 4242
await client.ConnectAsync(IPAddress.Loopback, 4242);
// send test message
await client.EnqueueMessageAsync(Encoding.UTF8.GetBytes("Anyone there?"));
Icon
Icon made by Smashicons from flaticon.com
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- Memowned (>= 0.3.2)
- ValueTaskSupplement (>= 1.1.0)
-
net6.0
- Memowned (>= 0.3.2)
- ValueTaskSupplement (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.