## ✨Simple example **_The following only examples are created in the simplest way. For more details, please see [Explanation Document](http://rrqm_home.gitee.io/touchsocket)。_** **【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: - Byte mode (1+n), one -time receives a maximum of 255 bytes. - USHORT mode (2+n), maximum receiving 65535 bytes. - INT mode (4+n), a maximum receiving 2G data at a time. 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 Thank you for your support for TouchSocket. If you have any other questions, please submit it, or add a group of QQ: 234762506 discussion. ## Support author [Support entrance](https://rrqm_home.gitee.io/touchsocket/docs/donate)