Flare.Tcp 0.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Flare.Tcp --version 0.2.2
NuGet\Install-Package Flare.Tcp -Version 0.2.2
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.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Flare.Tcp --version 0.2.2
#r "nuget: Flare.Tcp, 0.2.2"
#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.2

// Install Flare.Tcp as a Cake Tool
#tool nuget:?package=Flare.Tcp&version=0.2.2

Flare.Tcp

nuget badge Unlicense

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 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.3 396 7/9/2021
0.2.2 309 4/1/2021
0.2.1 341 2/15/2021
0.2.0 315 2/15/2021
0.1.0 385 12/2/2020