


When designing the software system architecture of the simple programmable controller, I have the following main considerations:
(1) need to support TCP server as well as TCP client multiplexed concurrently, TCP server has three cases of connection, the browser downloads the built-in web page and the communication after that, for the communication connection of the third-party software, for the connection of Modbus-TCP protocol;
The TCP client is used to connect to the TCP server on the cloud server to realize remote access. Considering the resource situation of ESP8266, the concurrency is designed according to the specification that the TCP server supports four TCP client connection while one TCP client connects to the cloud server;
(2) It is necessary to control the flow of up to 5-way TCP/IP data communication and allocate enough time slices for PLC-related task scheduling to ensure reliable scheduling of PLC functions and real-time response;
3) The main tasks are the LWIP task and the main task, the priority of the LWIP task is lower than that of the main task, and at the same time ensure that the main task does not have a long time-consuming or blocking task, and the main task is scheduled in 10ms tick, and it actively enters the blocking state after the execution of the main task, releasing the CPU for scheduling other tasks;
Combining these, I designed the nearby software architecture;
When TCP server or TCP client receives data, the task of LWIP executes the callback function for data reception;
In the callback function, the program just stores the received data into the receive buffer, but does not process the data;
There are five receive buffer, each used for five concurrent connections; when deposited into these buffer, the TCP packet unpacking and sticky packet situation is handled at the same time, HTTP protocol data is unpacked through the end of the rnrn characters;
When new data is received, the task of LWIP wakes up the main task to process it by signaling Semaphore.
Each time the main task detect status of these 5 buffers, and if there is received data, it processes the relevant data and generates a response back to the sender;
In order to ensure that all 5 connections have the same chance to be processed, the main task takes turns to prioritize the state of these 5 caches.
For example, if the scheduler determines the cache for connection 0 first, then the next scheduler determines the cache for connection 1.
This can be achieved with a simple code;
signed short http_get_recvs(U32 *msg, U32 *addr, U16 *port){
U8 i;
signed short res = -1;
for(i = 0; i
{
if(tcpclient_curquery_client >= TCPSERVER_CLIENT_NUM){ tcpclient_curquery_client = 0; } if(tcpclient_info[tcpclient_curquery_client].used == TRUE){ if(tcpclient_info[tcpclient_curquery_client].received){ *msg = (U32)tcpclient_info[tcpclient_curquery_client].recvbuff; *addr = tcpclient_info[tcpclient_curquery_client].ipaddr; *port = tcpclient_info[tcpclient_curquery_client].port; res = (signed short)tcpclient_curquery_client; break; } } tcpclient_curquery_client++; } return(res);
}
The above is the detailed content of How to ensure oncurrent TCP connection for ESPased programmable controller. For more information, please follow other related articles on the PHP Chinese website!

XML is used in C because it provides a convenient way to structure data, especially in configuration files, data storage and network communications. 1) Select the appropriate library, such as TinyXML, pugixml, RapidXML, and decide according to project needs. 2) Understand two ways of XML parsing and generation: DOM is suitable for frequent access and modification, and SAX is suitable for large files or streaming data. 3) When optimizing performance, TinyXML is suitable for small files, pugixml performs well in memory and speed, and RapidXML is excellent in processing large files.

The main differences between C# and C are memory management, polymorphism implementation and performance optimization. 1) C# uses a garbage collector to automatically manage memory, while C needs to be managed manually. 2) C# realizes polymorphism through interfaces and virtual methods, and C uses virtual functions and pure virtual functions. 3) The performance optimization of C# depends on structure and parallel programming, while C is implemented through inline functions and multithreading.

The DOM and SAX methods can be used to parse XML data in C. 1) DOM parsing loads XML into memory, suitable for small files, but may take up a lot of memory. 2) SAX parsing is event-driven and is suitable for large files, but cannot be accessed randomly. Choosing the right method and optimizing the code can improve efficiency.

C is widely used in the fields of game development, embedded systems, financial transactions and scientific computing, due to its high performance and flexibility. 1) In game development, C is used for efficient graphics rendering and real-time computing. 2) In embedded systems, C's memory management and hardware control capabilities make it the first choice. 3) In the field of financial transactions, C's high performance meets the needs of real-time computing. 4) In scientific computing, C's efficient algorithm implementation and data processing capabilities are fully reflected.

C is not dead, but has flourished in many key areas: 1) game development, 2) system programming, 3) high-performance computing, 4) browsers and network applications, C is still the mainstream choice, showing its strong vitality and application scenarios.

The main differences between C# and C are syntax, memory management and performance: 1) C# syntax is modern, supports lambda and LINQ, and C retains C features and supports templates. 2) C# automatically manages memory, C needs to be managed manually. 3) C performance is better than C#, but C# performance is also being optimized.

You can use the TinyXML, Pugixml, or libxml2 libraries to process XML data in C. 1) Parse XML files: Use DOM or SAX methods, DOM is suitable for small files, and SAX is suitable for large files. 2) Generate XML file: convert the data structure into XML format and write to the file. Through these steps, XML data can be effectively managed and manipulated.

Working with XML data structures in C can use the TinyXML or pugixml library. 1) Use the pugixml library to parse and generate XML files. 2) Handle complex nested XML elements, such as book information. 3) Optimize XML processing code, and it is recommended to use efficient libraries and streaming parsing. Through these steps, XML data can be processed efficiently.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
