Longbow.Sockets 9.0.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Longbow.Sockets --version 9.0.2
                    
NuGet\Install-Package Longbow.Sockets -Version 9.0.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="Longbow.Sockets" Version="9.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Longbow.Sockets" Version="9.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Longbow.Sockets" />
                    
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.Sockets --version 9.0.2
                    
#r "nuget: Longbow.Sockets, 9.0.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.
#:package Longbow.Sockets@9.0.2
                    
#: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.Sockets&version=9.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Longbow.Sockets&version=9.0.2
                    
Install as a Cake Tool

Longbow.Sockets

Longbow.Sockets is a high-performance .NET library for handling socket-based communication. It focuses on simplifying the process of receiving, parsing, and processing binary data packets, suitable for industrial protocols, IoT communication, Modbus, TCP/UDP scenarios, and more.

The library provides flexible packet handling mechanisms, data converters, property mapping, CRC validation, and supports custom protocols and data structures.


🚀 Main Features

  • Packet Handling

    • Supports fixed-length packets, delimiter-based packets, and other common formats.
    • Provides base classes for custom packet parsing logic.
  • Data Conversion

    • Supports automatic conversion of basic types (int, long, float, double, string, byte[], etc.).
    • Supports BigEndian / LittleEndian conversion.
    • Supports mapping of enums, custom types, and nested objects.
    • Supports defining field offset, length, encoding, etc. via attributes.
  • Property Mapping

    • Use DataPropertyConverterAttribute to map class properties to fields.
    • Supports custom converters (IDataPropertyConverter).
  • Logging Support

    • Provides a unified logging interface, supports injecting ILogger implementations.
  • CRC Validation

    • Built-in Modbus CRC16 algorithm for data integrity checks.
  • Encoding Tools

    • Includes BinConverter and HexConverter utility classes for converting between byte arrays and strings.

📦 Installation

You can install Longbow.Sockets via NuGet:

dotnet add package Longbow.Sockets

🛠️ Quick Start

Define Data Model

Use DataPropertyConverterAttribute to define your data structure:

[DataTypeConverter(Type = typeof(DataConverter<MyDataModel>))]
public class MyDataModel
{
    [DataPropertyConverter(Offset = 0, Length = 2, Type = typeof(ushort))]
    public ushort Header { get; set; }

    [DataPropertyConverter(Offset = 2, Length = 4, Type = typeof(int))]
    public int Value { get; set; }

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

Receive and Parse Packets

var handler = new FixLengthDataPackageHandler(16); // Assume each packet is 16 bytes
var adapter = new DataPackageAdapter();

adapter.ReceivedCallBack = async (data) =>
{
    var converter = new DataConverter<MyDataModel>();
    if (converter.TryConvertTo(data, out var model))
    {
        Console.WriteLine($"Header: {model.Header}, Value: {model.Value}, Message: {model.Message}");
    }
};

handler.ReceivedCallBack = adapter.HandlerAsync;

await handler.HandlerAsync(dataBuffer); // Receive data

Usage Examples

Handle Packets with Delimiter

var handler = new DelimiterDataPackageHandler("\r\n"); // Use \r\n as delimiter
handler.ReceivedCallBack = async (data) =>
{
    var text = Encoding.UTF8.GetString(data.Span);
    Console.WriteLine("Received: " + text);
};

await handler.HandlerAsync(dataBuffer);

CRC Validation

var dataWithCrc = ModbusCrc16.Append(dataWithoutCrc);
bool isValid = ModbusCrc16.Validate(dataWithCrc);

🤝 Contributing

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


📄 License

This project is licensed under the Apache License. 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.Sockets:

Package Downloads
Longbow.TcpSocket

Longbow extensions of TcpSocket

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.4 104 9/20/2025
9.0.3 455 9/16/2025
9.0.2 204 9/15/2025
9.0.1 134 9/14/2025
9.0.0 217 9/10/2025