Apache License 2.0

项目介绍

RRQM/TouchSocket 是一个托管在 GitHub 上的开源项目,主要使用 C# 编写,采用 Apache License 2.0 许可证,目前获得 1.3k 个 Star、205 次 Fork。

仓库全名
RRQM/TouchSocket
开源许可证
Apache License 2.0
Star 数
1.3k
Fork 数
205
未关闭 Issue
7

README 摘要

En | 中文 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…

完整内容见 GitHub 原始 README 或本页 。

常见问题

TouchSocket 用什么语言开发?

主要使用 C# 编写,采用 Apache License 2.0 许可证,目前有 1.3k 个 Star。

TouchSocket 可以免费商用吗?

仓库采用 Apache License 2.0 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 TouchSocket 的源码?

可以直接克隆仓库:git clone https://github.com/RRQM/TouchSocket.git,默认分支为 master;安装与运行步骤见仓库 README。

TouchSocket 最近还在维护吗?

仓库最近一次更新为 1 周前,当前有 7 个未关闭 Issue;Star 数为 1.3k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

TouchSocket is an integrated .NET networking framework that includes modules for socket, TCP, UDP, SSL, named pipes, HTTP, WebSocket, RPC, and more. It offers a one-stop solution for TCP packet issues and enables quick implementation of custom data message parsing using protocol templates.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
1720
价值分
836
活跃状态
活跃

语言占比

C#
MDX
PowerShell
TypeScript

Release

README

En | 中文

TouchSocket logo

TouchSocket

A simple, modern, and high-performance .NET networking framework

NuGet version NuGet downloads License GitHub stars Gitee stars QQ Group

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

TouchSocket 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. The TouchSocketPro. 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

TouchSocket is a member of the dotNET China organization.

评论

暂无评论