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
<PackageReference Include="Longbow.TcpSocket" Version="9.0.11" />
<PackageVersion Include="Longbow.TcpSocket" Version="9.0.11" />
<PackageReference Include="Longbow.TcpSocket" />
paket add Longbow.TcpSocket --version 9.0.11
#r "nuget: Longbow.TcpSocket, 9.0.11"
#:package Longbow.TcpSocket@9.0.11
#addin nuget:?package=Longbow.TcpSocket&version=9.0.11
#tool nuget:?package=Longbow.TcpSocket&version=9.0.11
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.
🔗 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
- Longbow.Sockets (>= 9.0.3)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
-
net7.0
- Longbow.Sockets (>= 9.0.3)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
-
net8.0
- Longbow.Sockets (>= 9.0.3)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.9)
-
net9.0
- Longbow.Sockets (>= 9.0.3)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.9)
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.
|