Longbow.TcpSocket 9.0.11

Prefix Reserved
dotnet add package Longbow.TcpSocket --version 9.0.11
                    
NuGet\Install-Package Longbow.TcpSocket -Version 9.0.11
                    
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="Longbow.TcpSocket" Version="9.0.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Longbow.TcpSocket" Version="9.0.11" />
                    
Directory.Packages.props
<PackageReference Include="Longbow.TcpSocket" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Longbow.TcpSocket --version 9.0.11
                    
#r "nuget: Longbow.TcpSocket, 9.0.11"
                    
#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.
#:package Longbow.TcpSocket@9.0.11
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Longbow.TcpSocket&version=9.0.11
                    
Install as a Cake Addin
#tool nuget:?package=Longbow.TcpSocket&version=9.0.11
                    
Install as a Cake Tool

Longbow.TcpSocket

Longbow.TcpSocket is a TCP socket communication library based on the .NET platform, providing a simple and easy-to-use API for asynchronous TCP communication. It supports automatic receiving, auto-reconnect, packet adapters, and more, making it suitable for building high-performance network communication applications.

🚀 Features

  • Asynchronous Communication: Uses ValueTask for high-performance asynchronous TCP communication.
  • Automatic Receiving: Supports automatic data stream reception, simplifying data processing logic.
  • Auto-Reconnect: Automatically attempts to reconnect when the connection is lost.
  • Packet Handler: Handles sticky packets and packet splitting issues.
  • Packet Adapter: Supports custom packet parsing logic.
  • Logging Support: Optional logging functionality for debugging and monitoring.
  • Dependency Injection Integration: Seamlessly integrates with .NET dependency injection frameworks.

📦 Installation

You can install Longbow.TcpSocket via NuGet:

dotnet add package Longbow.TcpSocket

🛠️ Quick Start

1. Register Services

Register the service in Startup.cs or Program.cs:

services.AddTcpSocketFactory();

Then obtain or create a client instance via ITcpSocketFactory:

var factory = serviceProvider.GetRequiredService<ITcpSocketFactory>();
var client = factory.GetOrCreate("myClient", options => 
{
    options.IsAutoReconnect = true;
});

Create a TCP Client and Connect to Server

using Longbow.TcpSocket;

var factory = serviceProvider.GetRequiredService<ITcpSocketFactory>();
var client = factory.GetOrCreate("myClient", options => 
{
    options.IsAutoReconnect = true;
});

client.ReceivedCallback = async (data) =>
{
    Console.WriteLine($"Received: {Encoding.UTF8.GetString(data)}");
};

await client.ConnectAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080));

Use Packet Adapter for Custom Data Formats

using Longbow.TcpSocket;

var factory = serviceProvider.GetRequiredService<ITcpSocketFactory>();
var client = factory.GetOrCreate("myClient", options => 
{
    options.IsAutoReconnect = true;
});

// Set packet adapter
client.AddDataPackageAdapter<MockEntity>(new FixLengthDataPackageHandler(12), OnReceive);

// Connect to remote
await client.ConnectAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080));

Task OnReceive(MockEntity entity)
{
    Console.WriteLine($"Received Entity: Id={entity.Id}, Name={entity.Name}");
    return Task.CompletedTask;
}

[DataTypeConverter(Type = typeof(DataConverter<MockEntity>))]
class MockEntity
{
    [DataPropertyConverter(Type = typeof(int), Offset = 4, Length = 2)]
    public int Id { get; set; }

    [DataPropertyConverter(Type = typeof(string), Offset = 6, Length = 4, EncodingName = "utf-8")]
    public string? Name { get; set; }
}

🤝 Contributing

Contributions to code and documentation are welcome! Please refer to CONTRIBUTING.md for more information.

📄 License

This project is licensed under the Apache License. Please see the LICENSE file for details.

📞 Contact

To contact the developers, please visit the project homepage or submit issues to Github Issues

Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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 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.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Longbow.TcpSocket:

Package Downloads
Longbow.Modbus

Longbow extensions of Modbus

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Longbow.TcpSocket:

Repository Stars
dotnetcore/BootstrapBlazor
Bootstrap Blazor is an enterprise-level UI component library based on Bootstrap and Blazor.
Version Downloads Last Updated
9.0.11 199 9/18/2025
9.0.10 228 9/17/2025
9.0.9 260 9/17/2025
9.0.8 206 9/16/2025
9.0.7 115 9/13/2025
9.0.6 134 9/10/2025
9.0.5 155 9/9/2025
9.0.4 138 9/6/2025
9.0.3 109 9/5/2025
9.0.2 88 9/5/2025
9.0.1 147 9/4/2025
9.0.0 140 9/3/2025