This action will force synchronization from 若汝棋茗/TouchSocket, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
雄关漫道真如铁,而今迈步从头越。从头越,苍山如海,残阳如血。
English | 中文
【Open source version】
Nuget | Url | Describe |
---|---|---|
Gitee Github |
TouchSocket is a lightweight, comprehensive network communication library that supports plug-in. Basic communication functions include TCP, UDP, SSL, RPC, HTTP, etc. Among them, HTTP server supports extended plugins such as WebSocket, Static web pages, XMLRPC, Webapi, JSONRPC . Touchrpc with a custom protocol, support SSL encryption, asynchronous calls, permissions management, error status return, service recovery, distributed calls, etc. When the empty load function executes, 100,000 calls are only 3.8 seconds, and only 0.9 seconds when the state is not returned. |
|
Gitee Github |
TouchSocket.AspNetCore is an exclusive version suitable for Aspnetcore. |
【Enterprise version】
Nuget | Url | Describe |
---|---|---|
Gitee Github |
TouchSocketpro is the enterprise version of TouchSocket, which is based on the original. There are also some corporate versions. For details, please see Enterprise Edition Related |
|
Gitee Github |
TouchSocketpro.aspnetcore is an exclusive version suitable for Aspnetcore. |
TouchSocket's IOCP is not the same as tradition. Take the official example of Microsoft as an example. Receive data,Then process the copy of the data. And TouchSocket takes a available memory block from the memory pool each time before receiving, and then is directly used to receive. After receiving the data, it will directly throw this memory block and process it. Operation, although it is only a small design, when the data of the transmission 10W times 64KB, the performance is different 10 times。
I believe that everyone has used other socket products, so TouchSocket also borrows the excellent design concept of other products during design. Data processing adapter is one of them, but unlike the design of other products, TouchSocket's adapter functions are more powerful. Easy to use and flexible. It can not only analyze the data packet in advance, but also parse the data object, which can be replaced at any time, and then take effect immediately. For example: the data can be pre -processed using a fixed Baotou to solve the problem of data subcontracting and sticky bags. You can also directly analyze the http data protocol, WebSocket data protocol, etc.
TouchSocket offers a variety of framework models that can be fully compatible with all protocols in the TCP and UDP protocols. For example: TCPSERVICE and TCPClient, their basic functions are exactly the same as sockets, but they only enhance the framework of the framework and concurrent and connect and to receive data. Out, allowing users to use more friendly use.
The following only examples are created in the simplest way. For more details, please see Explanation Document。
【TcpService】
TcpService service = new TcpService();
service.Connecting = (client, e) => { };//Some client is connecting
service.Connected = (client, e) => { };//There is a client connection
service.Disconnected = (client, e) => { };//There is a client that is cut off and connected
service.Received = (client, byteBlock, requestInfo) =>
{
//从客户端收到信息
string mes = byteBlock.ToString();
Console.WriteLine($"Receive information from {client.id}:{mes}");
client.Send(mes);//Return the received information directly to the sender
//client.Send("id",mes);//Return the received information to the client with a specific ID
var clients = service.GetClients();
foreach (var targetClient in clients)//Return the received information to all the clients online。
{
if (targetClient.ID != client.ID)
{
targetClient.Send(mes);
}
}
};
service.Setup(new TouchSocketConfig()//Load
.SetListenIPHosts(new IPHost[] { new IPHost("127.0.0.1:7789"), new IPHost(7790) })//At the same time, listen to two addresses
.SetMaxCount(10000)
.SetThreadCount(100))
.Start();//start up
【TcpClient】
TcpClient tcpClient = new TcpClient();
tcpClient.Connected = (client, e) => { };//Successfully connect to the server
tcpClient.Disconnected = (client, e) => { };//The connection is disconnected from the server, and it will not be triggered when the connection is unsuccessful.
tcpClient.Received = (client, byteBlock, requestInfo) =>
{
//Receive information from the server
string mes = Encoding.UTF8.GetString(byteBlock.Buffer, 0, byteBlock.Len);
Console.WriteLine($"Receive information: {MES}");
};
//Declaration configuration
TouchSocketConfig config = new TouchSocketConfig();
config.SetRemoteIPHost(new IPHost("127.0.0.1:7789"))
.UsePlugin()
.SetBufferLength(1024 * 10);
//Load
tcpClient.Setup(config);
tcpClient.Connect();
tcpClient.Send("RRQM");
【TcpClient Break】 In the config plug -in configuration, you must first enable the plug -in, and then use the re -connected plug -in.
.UsePlugin()
.ConfigurePlugins(a=>
{
a.UseReconnection(5, true, 1000);
});
【FixedHeaderPackageAdapter Pack】
This adapter mainly solves the problem of TCP adhesion package. The data format adopts a simple and efficient "Baotou+Data Body" mode. Among them, Baotou supports:
The above data header adopts the default end mode (small end mode) of TouchSocketbitConverter. Users can switch the default end mode according to the requirements.
TouchSocketBitConverter.DefaultEndianType = EndianType.Little;
【CustomFixedHeaderDataHandlingAdapter】
Users customize fixed Baotou adapters mainly help users solve data frame information with fixed Baotou. For example: The following data format needs to be implemented with only a few interfaces to complete the analysis. For detailed operations, please refer to the API.
|1|1|1|**********|
【CustomUnfixedHeaderDataHandlingAdapter】
Users customize non -fixed Baotou adapters mainly help users solve the data frame information with non -fixed Baotou. For example: the most typical HTTP packet, the data head and the data body are separated by "\r\n", and the data header is not fixed due to the different request information of the request request, and the length of the data body is not fixed, and the length of the data body is It is also specified by the value display of the data head, so you can consider using the CustomunfixedHeaderDatahandlingAdapter analysis, which can be achieved only through simple development.
Thank you for your support for TouchSocket. If you have any other questions, please submit it, or add a group of QQ: 234762506 discussion.
Thanks for the support of the following tools
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。