RRQM/TouchSocket
소개
TouchSocket은 소켓, TCP, UDP, SSL, 명명된 파이프, HTTP, WebSocket, RPC 등을 포함하는 통합 .NET 네트워킹 프레임워크입니다. TCP 패킷 문제를 한곳에서 해결할 수 있으며, 프로토콜 템플릿을 사용해 사용자 지정 데이터 메시지 파싱을 빠르게 구현할 수 있습니다.
시스템 및 인프라What you can do
- High-Performance IOCP - Each receive uses a writable block from the memory pool with zero extra copies; up to ~10× throughput vs. traditional implementations in 100k × 64KB stress tests
- Data Adapters - Fixed-header, fixed-length, terminator, HTTP, WebSocket templates; hot-swappable; automatic sticky/fragmented packet handling
- Plugin System - Reconnection, heartbeat, SSL, authentication, logging via .ConfigurePlugins() across the full communication lifecycle
- Unified API - TCP / UDP / WebSocket / NamedPipe / SerialPort all use ConnectAsync / SendAsync / Received
측정된 스타 증가
- in 24h
- 0
- in 7 days
- +2
- in 15 days
- +2
- in 1 month
- +3
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalEn | 中文
TouchSocket
A simple, modern, and high-performance .NET networking framework
Documentation · Getting Started · API Reference · Examples
30-Second Overview
TouchSocket is an integrated .NET networking framework covering TCP / UDP / WebSocket / HTTP / MQTT / Modbus / RPC / MCP and more. It ships with a memory pool, data-adapter pipeline, plugin system, DI / Hosting integration, and source generators.
Whether you are building a TCP server, an industrial device gateway, or an AI tool based on MCP, TouchSocket provides a unified API to get you there quickly.
Feature Map
Core Capabilities
| Capability | Description |
|---|---|
| High-Performance IOCP | Each receive uses a writable block from the memory pool with zero extra copies; up to ~10× throughput vs. traditional implementations in 100k × 64KB stress tests |
| Data Adapters | Fixed-header, fixed-length, terminator, HTTP, WebSocket templates; hot-swappable; automatic sticky/fragmented packet handling |
| Plugin System | Reconnection, heartbeat, SSL, authentication, logging via .ConfigurePlugins() across the full communication lifecycle |
| Unified API | TCP / UDP / WebSocket / NamedPipe / SerialPort all use ConnectAsync / SendAsync / Received |
| Memory Pool | ByteBlock, MemoryPool, Span / Memory optimized for low GC pressure under heavy traffic |
| Source Generators | AOT-friendly generation for RPC proxies, serialization, dependency properties, plugin raises |
| Multi-Target | .NET Framework 4.6.2 / .NET Standard 2.0 / .NET 6 / 8 / 10 |
Package Quick Reference
| Category | NuGet Package | One-Liner |
|---|---|---|
| Core | TouchSocket.Core |
Memory pool, ByteBlock, adapter base, IOC, logging, plugins, serialization |
| Transport | TouchSocket |
TCP / UDP / SSL, KCP, NAT, WaitingClient, sticky/fragment handling |
TouchSocket.NamedPipe |
Named-pipe IPC, ~3× faster than TCP | |
TouchSocket.SerialPorts |
Serial-port communication with adapter templates | |
TouchSocket.AspNetCore |
ASP.NET Core integration | |
TouchSocket.Hosting |
Generic Host support (Worker Service, etc.) | |
| HTTP / Web | TouchSocket.Http |
HTTP/1.1 server/client, WebSocket, large-file transfer |
TouchSocket.WebApi |
WebApi server + client with Swagger | |
TouchSocket.SocketIo |
Socket.IO client (v3/v4) | |
| RPC | TouchSocket.Rpc |
RPC platform: registration, dispatch, execution, invocation |
TouchSocket.Dmtp |
DMTP protocol: RPC, file transfer, channels, routing, Redis | |
TouchSocket.JsonRpc / TouchSocket.XmlRpc |
JSON / XML RPC | |
| IoT / Industrial | TouchSocket.Modbus |
Modbus RTU/ASCII/TCP master |
TouchSocket.Mqtt |
MQTT server / client | |
TouchSocket.Semi |
HSMS/SECS-II semiconductor protocols | |
TouchSocket.CoAP |
CoAP over UDP | |
TouchSocket.Redis |
Redis client + in-memory compatible server | |
| AI | TouchSocket.Mcp |
MCP server / client (stdio / Streamable HTTP) |
| Extensions | TouchSocket.Core.DependencyInjection / .Autofac |
Microsoft DI / Autofac adapters |
TouchSocket.Rpc.RateLimiting |
RPC rate limiting | |
*.*.SourceGenerator |
Source generators for each package |
All NuGet packages starting with
TouchSocket.are fully open-source and free for personal/commercial use. TheTouchSocketPro.line requires a commercial license.
Quick Start
Install
dotnet add package TouchSocket
Minimal TCP Server
var service = new TcpService();
service.Received = (client, e) =>
{
Console.WriteLine($"Received: {e.Memory.Span.ToString(Encoding.UTF8)}");
return EasyTask.CompletedTask;
};
await service.StartAsync(7789);
Minimal TCP Client
var client = new TcpClient();
client.Received = (c, e) =>
{
Console.WriteLine(e.Memory.Span.ToString());
return EasyTask.CompletedTask;
};
await client.ConnectAsync("127.0.0.1:7789");
await client.SendAsync("Hello");
Auto-Reconnect
client.ConfigurePlugins(a => a.UseReconnection<TcpClient>());
More examples are in examples.
Performance
| Implementation | Memory Handling | Performance Impact |
|---|---|---|
| Traditional IOCP (fixed buffer) | Received data must be copied again | Extra overhead under load |
| TouchSocket IOCP | Receives directly into a memory-pool block | Zero extra copies, significant gain at scale |
Stress test: 100k messages × 64KB — TouchSocket achieves up to ~10× the throughput of traditional implementations.
Named-pipe simple send/receive reaches 6.5 Gb/s, about 3× faster than TCP, with negligible GC.
Documentation
License & Support
TouchSocket is licensed under Apache License 2.0. All TouchSocket.* NuGet packages are free for personal and commercial use.
The TouchSocketPro.* line is commercially licensed. See Pro Edition for details.
Contact
- CSDN Blog
- Bilibili Videos
- QQ Group: 234762506
TouchSocket is a member of the dotNET China organization.
관련 프로젝트 살펴보기
불러오는 중…