Longbow.Sockets
9.0.4
Prefix Reserved
dotnet add package Longbow.Sockets --version 9.0.4
NuGet\Install-Package Longbow.Sockets -Version 9.0.4
<PackageReference Include="Longbow.Sockets" Version="9.0.4" />
<PackageVersion Include="Longbow.Sockets" Version="9.0.4" />
<PackageReference Include="Longbow.Sockets" />
paket add Longbow.Sockets --version 9.0.4
#r "nuget: Longbow.Sockets, 9.0.4"
#:package Longbow.Sockets@9.0.4
#addin nuget:?package=Longbow.Sockets&version=9.0.4
#tool nuget:?package=Longbow.Sockets&version=9.0.4
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
).
- Use
Logging Support
- Provides a unified logging interface, supports injecting
ILogger
implementations.
- Provides a unified logging interface, supports injecting
CRC Validation
- Built-in Modbus CRC16 algorithm for data integrity checks.
Encoding Tools
- Includes
BinConverter
andHexConverter
utility classes for converting between byte arrays and strings.
- Includes
📦 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.
🔗 Related Links
📞 Contact
To contact the developers, please visit the project homepage or submit issues to Github Issues.
Product | Versions 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. |
-
net6.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
-
net7.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
-
net8.0
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.9)
-
net9.0
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.9)
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.