Basic.Tcp 2.0.0

Suggested Alternatives

Flare.Tcp

Install-Package Basic.Tcp -Version 2.0.0
dotnet add package Basic.Tcp --version 2.0.0
<PackageReference Include="Basic.Tcp" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Basic.Tcp --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Basic.Tcp, 2.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Basic.Tcp as a Cake Addin
#addin nuget:?package=Basic.Tcp&version=2.0.0

// Install Basic.Tcp as a Cake Tool
#tool nuget:?package=Basic.Tcp&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Basic.Tcp

nuget badge Unlicense

A basic asynchronous multi-client message-based event-driven tcp server (and client).

Using the BasicTcpServer

// create a new server that listens on port 4269
using var server = new BasicTcpServer(4269);

// attach event handlers
server.ClientConnected += clientId => {
    Console.WriteLine($"Client {clientId} connected.");
};
server.ClientDisconnected += clientId => {
    Console.WriteLine($"Client {clientId} disconnected.");
};
server.MessageReceived += (clientId, message) => {
    // echo message back to client
    server.EnqueueMessage(clientId, message.ToArray());
};

// wait for incoming connections
await server.ListenAsync();

Using the BasicTcpClient

// create a new client
using var client = new BasicTcpClient();

// attach message listener
client.MessageReceived += message => {
    // print message to console
    Console.WriteLine(Encoding.UTF8.GetString(message));
};

// connect to localhost
await client.ConnectAsync(IPAddress.Loopback, 4269);

// send test message
await client.SendMessageAsync(Encoding.UTF8.GetBytes("Anyone there?"));

// read next message from server
await client.ReadMessageAsync();

// disconnect
client.Disconnect();
  • net5.0

    • No dependencies.

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
2.0.0 234 11/9/2020
1.0.0 193 11/3/2020