A communication method and system
By using a communication method based on the TCP/IP information flow interface when communicating between devices/systems, using a preset message structure and affirmative response mechanism, it solves the difficulty in ensuring data integrity and consistency and poor fault tolerance in the prior art. and other issues have achieved efficient and stable communication.
Patent Information
- Application Number
- CN202011270233.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-13
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2040-11-13
AI Technical Summary
When communication between equipment/systems, the prior art has problems such as difficulty in ensuring data integrity and consistency, poor fault tolerance, large network performance consumption, and complex development.
Using the communication method based on the TCP/IP information flow interface, the preset message structure is used to transmit messages with the partner system to ensure that the serial number and processing capability of the confirmation message meet the expectations and send an affirmative response, so as to achieve rapid data consistency processing. and improve fault tolerance.
It realizes data integrity and fast consistency processing, has good fault tolerance and fast self-recovery functions, simplifies message encoding, improves the density of effective information per unit byte, and reduces network resource occupation and repeated connection consumption. , ensuring the stability and reliability of communication.
Smart Images

Figure CN113765976B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a communication method and system. Background Art
[0002] At present, there are three main communication schemes between equipment and systems, taking the logistics management system as an example: the business system (as the server) connects to the manufacturer's WCS system (logistics management system, as the client), and the manufacturer's WCS system adapts and forwards according to the HTTP communication protocol (Hypertext Transfer Protocol); the business system uses the OPC (OLE for Process Control) protocol to communicate directly with the manufacturer's WCS system; the business system uses the UDP protocol (User Datagram Protocol) to communicate directly with the manufacturer's WCS system. Among them, the business system uses HTTP to communicate with the manufacturer's WCS system. Since HTTP is stateless, the business system and the manufacturer's WCS system need to interact multiple times in a business process, and frequently perform three-way handshakes, which consumes network performance. In addition, the HTTP protocol uses the "whitespace-delimited" method for encoding, which contains a large number of spaces and carriage return characters. This encoding method contains a large amount of redundant content. At the same time, the HTTP message header also causes a large amount of content that is not needed in specific businesses in the communication data, which seriously affects the network performance; OPC communication does not support multi-threading and is complex to develop; UDP communication has the defects of being unreliable and unstable. If the network is not good, packet loss is likely to occur, and the accuracy of the task cannot be guaranteed.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] Data integrity and consistency cannot be guaranteed, fault tolerance is poor and rapid self-recovery is impossible, message encoding contains a lot of redundant content, abnormal devices cannot be detected quickly, network resource usage is high, repeated connections consume network performance, communication is unstable and unreliable, multi-threading is not supported, and development is complex. Summary of the invention
[0005] In view of this, the embodiments of the present invention provide a communication method and system, which can ensure data integrity and fast consistency processing, have good fault tolerance, have a fast self-recovery function, simplify message encoding, improve the density of effective information per unit byte, can quickly detect abnormal devices, effectively release network resources, avoid repeated connections to consume network performance, ensure stable and reliable communication, ensure the sequence and reliability of instructions, have high message interaction security, support multi-threading, reduce development complexity, and avoid unpacking and sticking packages.
[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a communication method is provided.
[0007] A communication method comprises: establishing a connection with a partner system based on a TCP / IP information stream interface; after successfully establishing the connection, transmitting messages with the partner system in a preset message structure, wherein, after receiving a confirmation message sent by the partner system, determining that the sequence number of the confirmation message sent by the partner system is an expected sequence number and that the confirmation message sent by the partner system can currently be processed, and then sending an affirmative response to the partner system.
[0008] Optionally, in the preset message structure, the message starts with a message start character and ends with a message end character, and when the message start character and the message end character are transmitted as message content, the message start character and the message end character as the message content are converted in advance according to the conversion rules.
[0009] Optionally, the message is transmitted in the form of a data packet, and the size of the data packet is equal to the number of processable byte streams.
[0010] Optionally, the message is converted into an ASCII character sequence of a given length during transmission, and the content of the message includes: a message start character, a confirmation request flag, a sequence number, a destination, a source, a message data application, and a message end character.
[0011] Optionally, it also includes pre-setting an idle time and a connection loss time; when no message from the partner system is received during the idle time, a virtual request message is sent to the partner system and the idle time is reset; when no message from the partner system is still not received during the reset idle time, the operation of sending the virtual request message to the partner system and resetting the idle time is repeated; when no message from the partner system is still not received after the set connection loss time, the connection with the partner system is disconnected.
[0012] Optionally, if the confirmation message sent by the partner system cannot be processed currently or the sequence number of the confirmation message sent by the partner system is not an expected sequence number, a negative response is sent to the partner system.
[0013] Optionally, the negative acknowledgement sent to the partner system includes a first type of negative acknowledgement and a second type of negative acknowledgement; if the sequence number of the confirmation message received from the partner system is an incorrect sequence number, the first type of negative acknowledgement is sent to the partner system; if the sequence number of the confirmation message received from the partner system is an expected sequence number, but the confirmation message from the partner system cannot be processed currently, the second type of negative acknowledgement is sent to the partner system.
[0014] Optionally, it also includes: sending a confirmation message to the partner system and waiting for the partner system to send an affirmative response or a negative response; if no affirmative response or negative response is received from the partner system within a specified time, resending the confirmation message to the partner system, and when the number of resending the confirmation message reaches a preset upper limit, still no affirmative response or negative response is received from the partner system, disconnecting the partner system; the negative response sent by the partner system includes the first type of negative response and the second type of negative response; if the second type of negative response sent by the partner system is received multiple times in succession, then after each time the second type of negative response is received from the partner system, waiting for a preset time and sending a confirmation message to the partner system again.
[0015] Optionally, the method is executed by a server or a client; the method also includes: after sending a first type of negative response to the partner system or receiving a first type of negative response from the partner system, entering an asynchronous mode with the partner system, in which no messages other than sequence number synchronization messages are transmitted to the partner system, and, in the case where the method is executed by the server, the server performs the following resynchronization action: the server sets the next expected incoming message sequence number and the next message sequence number to be sent of the server to preset values, and sends the sequence number synchronization message to the partner system, so that the partner system also sets the next expected incoming message sequence number and the next message sequence number to be sent of the partner system to the preset values; in the case where the method is executed by the client, receiving the sequence number synchronization message sent by the partner system, so as to set the next expected incoming message sequence number and the next message sequence number to be sent to the preset values according to the sequence number synchronization message sent by the partner system.
[0016] Optionally, if the sequence number of the received confirmation message from the partner system is the same as the sequence number of the previously received confirmation message, and the confirmation message from the partner system can be processed currently, the positive response is sent to the partner system.
[0017] Optionally, after receiving the unconfirmed message sent by the partner system, if the unconfirmed message cannot be processed, the unconfirmed message is discarded without notifying the partner system.
[0018] According to another aspect of an embodiment of the present invention, a communication system is provided.
[0019] A communication system, characterized in that it includes: a client and a server that are partner systems to each other, wherein: the client establishes a connection with the server based on a TCP / IP information stream interface; after the client successfully establishes a connection with the server, messages are transmitted between the client and the server in a preset message structure, wherein, for either the client or the server, after receiving a confirmation message sent by the partner system of that end, it is determined that the sequence number of the confirmation message is the expected sequence number and the message can be processed currently, and then an affirmative response is sent to the partner system of that end.
[0020] According to yet another aspect of the embodiments of the present invention, an electronic device is provided.
[0021] An electronic device includes: one or more processors; and a memory for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the communication method provided by an embodiment of the present invention.
[0022] According to yet another aspect of an embodiment of the present invention, a computer readable medium is provided.
[0023] A computer readable medium stores a computer program, which, when executed by a processor, implements a communication method provided by an embodiment of the present invention.
[0024] An embodiment of the above invention has the following advantages or beneficial effects: establishing a connection with a partner system based on a TCP / IP information flow interface; after successfully establishing the connection, transmitting messages with the partner system in a preset message structure, wherein, after receiving a confirmation message sent by the partner system, determining that the sequence number of the confirmation message sent by the partner system is the expected sequence number and that the confirmation message sent by the partner system can be processed at present, and then sending an affirmative response to the partner system. It can ensure data integrity and fast consistency processing, has good fault tolerance, has a fast self-recovery function, simplifies message encoding, improves the density of effective information per unit byte, can quickly detect abnormal devices, effectively release network resources, avoid repeated connections to consume network performance, stable and reliable communication, ensure the order and reliability of instructions, high message interaction security, support multi-threading, reduce development complexity, and avoid unpacking and sticking.
[0025] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0027] Figure 1is a schematic diagram of main steps of a communication method according to an embodiment of the present invention;
[0028] Figure 2 is a schematic diagram of a synchronization error recovery process according to an embodiment of the present invention;
[0029] Figure 3 is a schematic diagram of a communication process according to an embodiment of the present invention;
[0030] Figure 4 is a schematic diagram of the main components of a communication system according to an embodiment of the present invention;
[0031] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0032] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0033] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0034] Figure 1 It is a schematic diagram of main steps of a communication method according to an embodiment of the present invention.
[0035] like Figure 1 As shown, the communication method of an embodiment of the present invention mainly includes the following steps S101 to S102.
[0036] Step S101: Establishing a connection with a partner system based on a TCP / IP information flow interface;
[0037] Step S102: After the connection is successfully established, a message is transmitted with the partner system in a preset message structure, wherein, after receiving a confirmation message sent by the partner system, it is determined that the sequence number of the confirmation message sent by the partner system is the expected sequence number and the confirmation message sent by the partner system can be processed currently, and then an affirmative response is sent to the partner system.
[0038] In one embodiment, in a preset message structure, the message starts with a message start character and ends with a message end character, and when the message start character and the message end character are transmitted as message content, the message start character and the message end character in the message content are converted in advance according to the conversion rules.
[0039] Messages can be transmitted in the form of data packets, and the size of the data packet is equal to the number of processable byte streams.
[0040] In one embodiment, the message is converted into an ASCII character sequence of a given length during transmission, and the content of the message includes: a message start symbol, a confirmation request flag, a sequence number, a destination, a source, a message data application, and a message end symbol.
[0041] In one embodiment, an idle time and a connection loss time may be preset. When no message from the partner system is received during the idle time, a virtual request message is sent to the partner system and the idle time is reset. When no message from the partner system is still received during the reset idle time, the operation of sending the virtual request message to the partner system and resetting the idle time is repeated. When no message from the partner system is still received after the set connection loss time, the connection with the partner system is disconnected.
[0042] If the confirmation message sent by the partner system cannot be processed currently or the sequence number of the confirmation message sent by the partner system is not the expected sequence number, a negative response is sent to the partner system.
[0043] In one embodiment, the negative acknowledgement sent to the partner system includes a first type negative acknowledgement and a second type negative acknowledgement, that is, a certain negative acknowledgement sent to the partner system may be a first type negative acknowledgement or a second type negative acknowledgement.
[0044] If the sequence number of the confirmation message received from the partner system is an incorrect sequence number, a first type negative response is sent to the partner system; if the sequence number of the confirmation message received from the partner system is an expected sequence number, but the confirmation message of the partner system cannot be processed at present, a second type negative response is sent to the partner system.
[0045] The communication method of an embodiment of the present invention may further include: sending a confirmation message to the partner system and waiting for the partner system to send an affirmative response or a negative response; if no affirmative response or negative response is received from the partner system within a specified time, resending the confirmation message to the partner system, and when the number of resending the confirmation message reaches a preset upper limit, if no affirmative response or negative response is received from the partner system, disconnecting the partner system; the negative response sent by the partner system includes a first type of negative response and a second type of negative response; if the second type of negative response is received from the partner system for multiple consecutive times, after each time the second type of negative response is received from the partner system, waiting for a preset time and sending a confirmation message to the partner system again.
[0046] The communication method of the embodiment of the present invention may be executed by a server or a client.
[0047] After sending the first type of negative response to the partner system or receiving the first type of negative response from the partner system, the system enters an asynchronous mode with the partner system. In the asynchronous mode, no messages other than the sequence number synchronization message are transmitted with the partner system.
[0048] In the case where the communication method of the embodiment of the present invention is executed by the server, the server performs the following resynchronization action: the server sets the server's next expected incoming message sequence number and the next message sequence number to be sent to preset values, and sends a sequence number synchronization message to the partner system, so that the partner system also sets the partner system's next expected incoming message sequence number and the next message sequence number to be sent to preset values.
[0049] When the communication method of the embodiment of the present invention is executed by the client, a sequence number synchronization message sent by the partner system is received to set the next expected incoming message sequence number and the next message sequence number to be sent to preset values according to the sequence number synchronization message sent by the partner system.
[0050] If the sequence number of the confirmation message received from the partner system is the same as the sequence number of the confirmation message received previously, and the confirmation message of the partner system can be processed currently, a positive response is sent to the partner system.
[0051] When receiving an unconfirmed message sent by the partner system, if the unconfirmed message cannot be processed, the unconfirmed message is discarded without notifying the partner system.
[0052] It has been introduced above that the communication method of the embodiment of the present invention can be executed by the server or the client. In the case where the communication method of the embodiment of the present invention is executed by the server, the partner system refers to the client. In the case where the communication method of the embodiment of the present invention is executed by the client, the partner system refers to the server. That is, in the embodiment of the present invention, the client and the server are partner systems. The client establishes a connection with the server based on the TCP / IP information stream interface. After the connection is successfully established, the client and the server transmit messages in a preset message structure, wherein, when the first end of the client and the server sends a confirmation message to the second end, the second end determines that the sequence number of the confirmation message is the expected sequence number and the second end is currently able to process the message, and then sends an affirmative response to the first end. After receiving the affirmative response, the first end continues to send subsequent confirmation messages to the second end. Since the transmission of messages between the client and the server in a preset message structure is mutual, when the client transmits a message to the server, the client is the first end and the server is the second end; when the server transmits a message to the client, the server is the first end and the client is the second end.
[0053] The message in the embodiment of the present invention may be a confirmed message or an unconfirmed message.
[0054] For the confirmation message, if the message is correctly recognized and will be processed by the receiving end (i.e., the second end), the receiving end will reply that the message has been received. If the receiving end cannot process the received confirmation message due to internal congestion, etc., it will send a negative reply (negative acknowledgment) back to the sending end (i.e., the first end). Therefore, the confirmation message will not be lost without informing the sending end.
[0055] For unconfirmed messages, when the first end of the client and the server sends an unconfirmed message to the second end, if the second end cannot process the unconfirmed message, the unconfirmed message will be discarded without notifying the first end. For example, if the receiving end cannot process the received unconfirmed message due to internal congestion, the message will be directly discarded without notifying the sending end, so the unconfirmed message is likely to be lost. After sending an unconfirmed message, the sending end can only continue to send the next message, and there is no guarantee that there will be a response from the receiving end.
[0056] When the message is transmitted in the form of a data packet, the size of the data packet sent by the first end is equal to the number of byte streams that can be processed by the second end.
[0057] In one embodiment, the client and the server are respectively set with their own idle time and connection loss time. When one of the parties does not receive any message from the other party during the idle time, a virtual request message is sent to the other party and the idle time is reset. When any message from the other party is still not received during the reset idle time, the operation of sending the virtual request message to the other party and resetting the idle time is repeated. When any message from the other party is still not received after the set connection loss time, the connection with the other party is disconnected.
[0058] If the second end is currently unable to process the confirmation message or the sequence number of the confirmation message is not the expected sequence number, a negative response is sent to the first end.
[0059] If the first end does not receive a positive or negative response from the second end within a specified time, the confirmation message is resent; when the number of resending confirmation messages reaches a preset upper limit and still does not receive a positive or negative response from the second end, the first end disconnects.
[0060] In one embodiment, if the sequence number of the confirmation message received by the second end is an incorrect sequence number, a first type of negative response is sent to the first end; if the sequence number of the confirmation message received by the second end is an expected sequence number, but the second end is currently unable to process the message, a second type of negative response is sent to the first end. When the first end receives the second type of negative response from the second end for multiple consecutive times, after each receipt of the second type of negative response, the first end waits for a preset time and sends the confirmation message again.
[0061] In one embodiment, after the second end receives the first type of negative response, the first end and the second end enter an asynchronous mode. In the asynchronous mode, no messages other than sequence number synchronization messages are transmitted between the first end and the second end, and the server end between the first end and the second end performs the following resynchronization action: the server end sets the server end's next expected incoming message sequence number and the next message sequence number to be sent to preset values, and sends a sequence number synchronization message to the client end, so that the client end sets the client end's next expected incoming message sequence number and the next message sequence number to be sent to preset values.
[0062] In one embodiment, if the sequence number of the confirmation message received by the second end is the same as the sequence number of the confirmation message received previously, and the second end is currently able to process the message, then a positive response is sent to the first end.
[0063] The communication method of the embodiment of the present invention is based on an event-oriented, full-duplex, bilateral, reliable message communication protocol, which is specifically as follows: the data between systems is converted into messages, that is, they are defined as short data packets (20 to 120 bytes) with fixed descriptions. There is a point-to-point connection between the systems that must communicate with each other. The connection between the two systems is used for two-way data transmission, that is: each pair of systems that want to communicate with each other has one and only one direct connection, and this connection can be used for data from system A to system B, and can also be used for data from system B to system A.
[0064] The embodiment of the present invention supports a specific system to communicate with several other systems. The specific system has a separate connection with each partner system, supporting multi-threaded communication.
[0065] One of the two systems that perform message communication (or message transmission) is defined as the server and the other as the client. Taking the logistics management system as an example, the manufacturer's WCS can be defined as the client and the business party's WCS as the server. The manufacturer's WCS is the manufacturer's warehouse equipment management system, and the business party's WCS is the business party's logistics management system - the basic equipment logistics control automation system. The client can also be the manufacturer's PLC (programmable logic controller) device.
[0066] One of the two systems performing message transmission can be called the partner system of the other system. If an event occurs that must be reported to the partner system, each system can send data at any time. Only when there is a flow control and handshake mechanism in the message communication protocol of the embodiment of the present invention can data (i.e., messages) be safely transmitted between systems.
[0067] The communication in the embodiment of the present invention is based on the TCP / IP information stream interface connection. When the client starts, it will immediately try to establish a connection with the server. The server (such as the business party WCS) will create a listening interface with a fixed port number, and then wait to be called by the client (such as the manufacturer's WCS). When an incoming call is confirmed, it will be accepted by the server, and data will be exchanged after the connection is confirmed. The client calls the server through a fixed host and port number and tries to establish a connection. If the attempt fails, the client will wait for a while and try again; if the connection is accepted by the server, data will be exchanged after the connection is confirmed OK.
[0068] The server will not determine any specific client IP address or client port number, that is, calls from any source will be accepted. If business needs require, security policies including but not limited to IP verification, port verification, MAC address verification or TOKEN value verification can be added to ensure the reliability and stability of the client source.
[0069] Once a connection is established successfully, it will remain active. Usually, the connection will only be disconnected in one of the following situations: the system detects a communication problem with the connection (such as a failure to read or send the connection); the system encounters a partner system response timeout or failure; or a manual request to disconnect is made during system maintenance.
[0070] All data transmissions using the communication protocol of the present invention are applicable to ASCII character streams. When sending data, the data is converted into ASCII characters of a given length, that is, the message is converted into an ASCII character sequence of a given length when it is transmitted. There are two basic data types that can be used: one is ALPHA n, which is a sequence of exactly n ASCII characters. All characters from "!" to Except for "<", ">", all characters are allowed. If the length is insufficient, spaces can be used to fill the string. The second is NUM n, which is a sequence of exactly n ASCII characters between "0" and "9", describing a number.
[0071] The content of the message may include: message start symbol, confirmation request flag, sequence number, destination, source, message data application, check bit, message end symbol, etc. Since the message communication of the embodiment of the present invention is based on TCP, and TCP is a stream protocol, there is no direct way to automatically detect the range of the message. Therefore, the message structure of the embodiment of the present invention defines that the message starts with the message start symbol "<" and ends with the message end symbol ">". The sender (i.e., the first end) in the client and the server must put each message in the correct structure, especially to start and end the message with "<" and ">" respectively. The receiving end (i.e., the second end) needs to scan out valid messages, that is, from one "<" to the next ">" as a valid message, and the content between each ">" and the next "<" will be considered as impurities in the connection, and the receiving end will ignore this part. If another "<" appears in the message structure, the receiving end will regard it as the beginning of a new structure, and regard the content between the previous "<" and the "<" as a structural error and ignore it. The receiving end can issue a local warning message after detecting impurities or structural errors.
[0072] In some embodiments, the message structure may also adopt an extended data structure (or an extended message structure). For example, the program requires the function of sending “<” and ">” characters in the program data, that is, “<” and ">” are part of the message content. Then, the message start symbol and the message end symbol may be converted in advance according to the conversion rules. For example, when sending data to the TCP / IP interface, “%)” may be used to represent “>”, “%(” may be used to represent “<”, and “%%” may be used to represent “%”. Other characters are sent as they are. When the message is received, “%)” is converted into “>”, “%(” is converted into “<”, and when C is any character other than “)” or “(”, “%C” may be converted into “C”, and other character combinations are received as they are. For the example where the extended data structure is not used, all characters in the program are sent and received as they are, that is, the characters in the message content do not include “<” and ">”, and “<” and ">” are only used as message start symbols and message end symbols. The embodiment of the present invention may pre-configure whether to use the extended data structure.
[0073] The embodiment of the present invention can configure the message to be transmitted in the form of a data packet, that is, the embodiment of the present invention can provide an option that the sender should send data in a fixed-size data packet. Since some systems, such as a PLC system, cannot reasonably process unspecified byte streams, therefore, in the embodiment of the present invention, when the message structure to be sent is shorter than a preset fixed size, the data (message) will be filled with padding characters to the size. When the message structure to be sent is exactly the fixed size, no operation is required. When the message structure to be sent is larger than the fixed size, the data (message) will be filled with padding characters to an integer multiple of the size. The above padding is performed outside the message structure. In the embodiment of the present invention, even if the configured data packet size is long enough, the sender cannot place more than one message in one data packet. When the data packet size is 1, each byte will be processed separately, and the byte stream will be truly treated as a stream of bytes. If the receiving end configured to process a byte stream (i.e., the data packet size is 1) can process a larger configured data packet, since the padding characters are performed outside the message structure, the padding characters will be directly ignored as impurities.
[0074] For each connection, the parameters that depend on the TCP / IP network settings are shown in Table 1. The client host name / IP address and port number are not configurable.
[0075] Table 1
[0076]
[0077] In an embodiment of the present invention, if a system disconnects itself, or detects that the connection is disconnected by a partner system or an external factor, the system will enter a communication setup state. Specifically, if the system is a server, it will wait to be called again, and if the system is a client, it will repeatedly try to re-establish the connection.
[0078] In some cases, one system may think that a connection has been established, but its partner system thinks that no connection has been established, which may cause the connection to fail to recover automatically. To this end, the embodiment of the present invention uses a receive timeout and a message to maintain a heartbeat function. Specifically, the systems (client or server) that communicate with each other are set with their own idle time and connection loss time. When one party (for example, system A) does not receive any message from the other party (for example, system B) during the idle time, a virtual request message, i.e., a DUM message, is sent to the other party (system B). After sending the DUM message, the party (system A) will reset its own idle time. After receiving the DUM message, the other party (system B) will send a DUA response to the party that sent the DUM message (system A). After receiving the DUA response, system A will reset its own idle time again. This process is shown in Table 2.
[0079] Table 2
[0080]
[0081] For any party in the communication connection (server or client), a DUM message will be sent to the partner system when the idle time expires.
[0082] When one party does not send a DUM message to the partner system but unexpectedly receives a DUA response from the partner system, the DUA response will be ignored, but the idle time will still be reset.
[0083] The receipt of any message (whether correct or valid) will reset the idle time. Therefore, if a station (or system) continues to send program messages and the interval between two program messages is shorter than the idle time, then the station (system) receiving these messages will never send DUM.
[0084] After sending a DUM message, the idle time will be reset. After sending a DUM message, if no message from the partner system is received within the idle time, the DUM will be sent again. If a message other than a DUA response is received after sending a DUM message, the idle time will also be reset. DUA does not contain any information, and the party receiving the DUM can also respond with other messages besides the DUA response.
[0085] If the site (system) does not receive any message from the partner system within the connection loss time (i.e. "connection loss timeout"), it will consider the partner system to be dead and disconnect. After that, depending on whether the site is configured as a client or a server on the TCP / IP platform, the site will try to reconnect or wait for the partner system to reconnect. The process is shown in Table 3.
[0086] Table 3
[0087]
[0088]
[0089] Any received message will reset the connection loss time. The connection loss timeout (i.e., connection loss time, or link loss timeout) must be longer than the idle timeout (i.e., idle time), otherwise the connection will be disconnected before the DUM message is sent for detection. The connection loss time is calculated from the time any message is received, not from the time the DUM is sent. For example, see Table 4.
[0090] Table 4
[0091]
[0092] The message of the embodiment of the present invention can be a confirmed message or an unconfirmed message. The unconfirmed message is sent by the sending end (i.e., the first end). If the receiving end (i.e., the second end) cannot process the received unconfirmed message due to internal congestion, the message will be directly discarded without informing the sending end, which means that the unconfirmed message is likely to be lost. After the sending end sends the unconfirmed message, it can only continue to send the next one, and there is no guarantee that there will be a response.
[0093] The confirmation message is sent by the sender. If the message is correctly recognized and processed by the receiver, the receiver replies that it has received the message. If the receiver cannot process the received confirmation message due to internal congestion, it will send a negative acknowledgment back to the sender. The confirmation message will not be lost without informing the sender. After the sender of the confirmation message receives the positive acknowledgment, it can continue to send the next message.
[0094] If the sender receives a negative response indicating that the buffer is full, it will wait for a preset time (i.e., the preset buffer full timeout) and then resend the message. If the sender does not receive any (positive or negative) response from the receiver within a specified time (i.e., the preset confirmation timeout), it will resend the message. The upper limit of the number of times the confirmation message is resent can be preset. If the sender does not receive any response, when the number of times the same message is repeatedly sent reaches the preset upper limit, if the last attempt still does not receive a response, the sender will disconnect.
[0095] Flow control is bidirectional. For example, A sends a message to B, but it has not been confirmed yet. B can still send a message to A. The transmission process of unconfirmed messages is shown in Table 5, where "(1)" and "(2)" in XXX(1) and XXX(2) represent message sequence numbers; the transmission process of confirmed messages is shown in Table 6, where "ACK response (1)" is taken as an example to represent a response message with sequence number 1; the message transmission when the receiving end buffer (or buffer) is full is shown in Table 7, where "NCK (full)" represents a negative response that the buffer is full (an example of the second type of negative response). If there is indeed a problem, the receiving end will reject the message more than once, and the sending end will try to send it endlessly; the message transmission when the receiving end has no response is shown in Table 8. In the following tables, A and B represent two communicating systems. If one is the server, the other is the client. "A to B" in the table means that the message transmission direction is from system A to system B. Similar situations will not be described below.
[0096] Table 5
[0097] serial number Message communication describe 0 Connection is OK 1 XXX(1) A to B Unconfirmed message sent 2 XXX(2) A to B The next unconfirmed message is sent ...and so on
[0098] Table 6
[0099] serial number Message communication describe 0 Connection is OK 1 XXX(1) A to B A confirmation message is sent 2 ACK (1) B to A The receiving end confirms receipt 3 XXX(2) A to B The next confirmation message is sent 4 ACK (2) B to A The receiving end confirms receipt ……etc
[0100] Table 7
[0101]
[0102]
[0103] Table 8
[0104]
[0105] As shown in Tables 5 to 8 above, each confirmation message contains a sequence number, which is used for the receiving end to determine whether the message is a duplicate message that has been received or a new message, and to determine whether the received message is consistent with expectations.
[0106] Unconfirmed messages do not have sequence numbers, that is, the sequence numbers in the structure are always set to 0000. Therefore, the following detailed description is mainly for confirmed messages. The message in the description of sequence numbers below refers to the confirmed message.
[0107] The sequence number of the confirmation message ranges from 0001 to 9999. Each new confirmation message sequence number increases by 1 compared to the previous confirmation message sequence number. The sequence number appears cyclically. If the sequence number of the previous confirmation message is 9999, the sequence number of the next confirmation message sent is 0001. When the synchronization message is used during resynchronization, the sequence number will be reset to a specific starting value (0001). 0000 is never used as the sequence number of the confirmation message. The sequence numbers of the two directions of message transmission are managed separately. For example, the sequence numbers from A to B and from B to A are separate. The sequence number is not message type-specific, that is, it is a count of all types of messages sent through a connection.
[0108] If the program in the system consists of different components that process different messages, the sequence number must be the responsibility of the communication component that manages the connection with the partner system. The confirmation message sequence number of the embodiment of the present invention is securely stored on a disk or the like for permanent storage.
[0109] For the sequence numbers processed by the sender: when a new confirmation message needs to be sent, the "next sequence number to be sent" is incremented by 1 and assigned to the message; after sending, wait for the response from the receiver; no other confirmation messages can be sent before receiving the response; if a positive response is received, the next message can be sent; if a negative "sequence error" response is received (that is, an example of the first type of negative response), it will enter the "out of sync" mode and no longer send any messages; if a negative "buffer full" response is received (that is, an example of the second type of negative response) or there is no response within the normal time, wait for a period of time and resend the message with the sequence number.
[0110] For the sequence number processed by the receiving end: if the received message is correct, that is, it contains the expected sequence number, the sender is replied to be processed by the receiving end; if the received message is a duplicate, that is, the sequence number is the same as the previous message, the sender is replied like a correct message (it is very likely that the previous ACK message is lost), but no processing is done on the message; if the received message has an incorrect sequence number (neither expected nor repeated with the previous one), a negative response of "sequence error" is given, the receiving end enters the "out of sync" mode, and the incoming call is not processed.
[0111] The transmission of confirmation messages in the case of duplicate messages is shown in Table 9; the transmission of confirmation messages in the case of sequence number errors is shown in Table 10.
[0112] Table 9
[0113]
[0114] Table 10
[0115]
[0116] Regardless of whether the sender sends an error message due to incorrect internal data, or the receiver misinterprets the message sequence number due to incorrect internal data, the result is the same, i.e., neither party sends any more messages. The receiver, if in out-of-sync mode, no longer receives application messages (including messages with correct sequence numbers), but still accepts and processes low-level messages (DUM, DUA, SYN). The receiver, if in out-of-sync mode, receives an acknowledged application message (acknowledgement message), directly replies with the NCK "sequence error" indication without any further checks, and the message is ignored. The sender, if in out-of-sync mode, no longer sends application messages (including messages with correct sequence numbers), but still sends low-level messages (DUM, DUA, NCK, SYN). Therefore, an out-of-sync situation prevents traffic in both directions, for example, if there is a problem in the direction A to B, and the stations (systems) enter out-of-sync mode, this also means that no acknowledgement messages are sent or received in the direction B to A.
[0117] The embodiment of the present invention solves the asynchronous problem by resynchronization. The server system can be started manually to perform manual intervention settings, or resynchronization can be automatically triggered (auto SYN). The synchronization error recovery process of an embodiment of the present invention is as follows Figure 2 As shown, Figure 2The synchronization error mode is the asynchronous mode. When the receiving end receives a negative response of a sequence number error (or sequence error), the communicating parties enter the asynchronous mode. The server sets the server's next expected incoming message sequence number and the next message sequence number to be sent to 0001, and sends a SYN message to the client, so that the client sets the client's next expected incoming message sequence number and the next message sequence number to be sent to 0001. The synchronization error recovery process can also be shown in Table 11.
[0118] Table 11
[0119]
[0120] In the above process, it is necessary to ensure that the connection between the two systems is up and running, otherwise it may happen that only one system returns to normal mode while the other system stays in out-of-sync mode. A system that is not in out-of-sync mode (client) also receives the SYN message and handles it in the same way, that is, the "next expected incoming sequence number" and "next sequence number to be sent" are both set to 0001. If there is an outstanding message that has not been answered, it will be resent with a sequence number of 0001. Resynchronization affects both directions. For example, even if only the sequence number in the A to B direction is out of sync, the next resynchronization setting will reset the sequence numbers in both the A to B and B to A directions to 0001.
[0121] When the connection between the system and its partner system is established, the following is performed: 1. Reset the timer (receive timing, link (connection) loss timing); 2. If a confirmation message has been sent but no response has been received, resend the message; 3. If there is no unresolved response, send the next message. The relevant parameters are shown in Table 12.
[0122] Table 12
[0123]
[0124] The message structure of the embodiment of the present invention, each message is composed of the content shown in Table 13:
[0125] Table 13
[0126]
[0127]
[0128] There is no direct low-level response for unconfirmed messages (confirmation request flag is 0), and the sender can send the next message immediately. For the corresponding confirmation message sent (confirmation request flag is 1), the receiving end will give a low-level ACK response (affirmative response) or NCK response (negative response). The sending end can only send the next confirmation message after this message is responded. Message structure errors will not be reported to the sending end. The receiving end only generates a local error and does not accept this message. The message communication protocol of the embodiment of the present invention does not include any routing and forwarding procedures. The receiving end only accepts messages whose destinations match itself, and other messages will be ignored.
[0129] If extended data structures are used, the characters <, >, and % must be handled in a special way. For example:
[0130] The program message contains the following data:
[0131] XTC0001 <xml-data>99%0102
[0132] will be converted to:
[0133] <00000ddddddssssssXTC0001%(XML-Data%)99%%010200>
[0134] The connection check / heartbeat message of the embodiment of the present invention is described in detail below. If one of the two parties of message transmission does not receive any message from the other party during the idle time, it sends a virtual request message, i.e., a DUM message, to the other party. The message layout is shown in Table 14.
[0135] Table 14
[0136] Data Description Field Type value Remark Message Type ALPHA 3 DUM Error Indicator NUM 1 0 Reserve Response sequence number NUM 4 0000 Reserve
[0137] Each site (system) can send a DUM message at any time. The DUM message is sent as an unconfirmed message (ie, in the structure, "confirmation request flag" == 0, "sequence number" == 0000).
[0138] The receiver of the DUM message must respond with a DUA message, i.e., a virtual response message. The layout of the DUA message is shown in Table 15.
[0139] Table 15
[0140]
[0141]
[0142] DUM and DUA messages are used to detect link (connection) failures in a timely manner when there is no other communication on the connection. If the expected DUA message is not received, the waiting station (system) needs to run the appropriate repair procedure. DUA messages are also sent as unconfirmed messages (i.e., in the structure, "confirmation request flag" == 0, "sequence number" == 0000).
[0143] The response message and the sequence number synchronization message according to the embodiment of the present invention are respectively introduced below.
[0144] The ACK message is an indication of successful message reception and can be sent by either party to confirm that the message has been successfully received. The message layout of the ACK message is shown in Table 16.
[0145] Table 16
[0146] Data Description Field Type value Remark Message Type ALPHA 3 ACK Error Indicator NUM 1 0 Reserve Response sequence number NUM 4 0001-9999 Confirm the sequence number of the message
[0147] When a station (system) receives a correct program message with a confirmation request marked as 1 in the message structure, that is, the message is a confirmation message, then an ACK with the confirmation message sequence number will be sent to the sender of the confirmation message. When a station (system) receives a duplicate confirmation program message (i.e., confirmation message), that is, the sequence number is smaller than expected, then an ACK with the duplicate sequence number will be sent to the sender of the duplicate message.
[0148] The incoming (correct) ACK message allows the sender of the original message to remove it from the send queue and send the next confirmation message. The ACK message is sent as an unconfirmed message (i.e. in the structure, "confirmation request flag" == 0, "sequence number" == 0000).
[0149] A negative acknowledgement message, i.e., an NCK message, is an indication of unsuccessful message reception and can be sent by either of the two communicating systems to confirm that the message was received and rejected. The message layout of the negative acknowledgement message is shown in Table 17.
[0150] Table 17
[0151]
[0152]
[0153] When a site (system) receives a confirmation program message (i.e., a confirmation message, in which the confirmation request is marked as 1 in the message structure), but the sequence number is neither the expected sequence number nor the correct sequence number of the previous message, an NCK message containing an error indicator == 1 and the next expected sequence number will be sent to the sender of the confirmation program message. The party receiving the NCK message with an incorrect sequence number will enter the sequence number error mode after receiving the NCK message with an incorrect sequence number. At this time, both parties will enter the asynchronous mode.
[0154] When a site (system) receives a confirmation program message (i.e., a confirmation message, in which the confirmation request is marked as 1 in the message structure), but cannot be stored due to insufficient current receive buffer space, an NCK message containing an error indicator == 2 and the next expected sequence number will be sent to the sender of the confirmation message. The party that receives the NCK message indicating that the buffer is full will wait for a preset time (i.e., a preset buffer full timeout time) and then resend the previous confirmation message. No other confirmation messages can be sent before this.
[0155] The incoming (correct) ACK message allows the sender of the original message to remove it from the send queue and send the next confirmation message. The NCK message is sent as an unconfirmed message (i.e. in the message structure, "confirmation request flag" == 0, "sequence number" == 0000).
[0156] The sequence number synchronization message, i.e., the SYN message, is used to request resynchronization of the sequence number. The server can send SYN to recover from the synchronization error mode. The message layout of the sequence number synchronization message is shown in Table 18.
[0157] Table 18
[0158] Data Description Field Type value Remark Message Type ALPHA 3 SYN Error Indicator NUM 1 0 Reserve Response sequence number NUM 4 0000 Reserve
[0159] SYN message can only be sent by the server side of the communication. SYN is divided into auto SYN and manual SYN. Among them, auto SYN means that after the server receives the NCK message with the wrong sequence number from the client, or after the server sends the NCK message with the wrong sequence number, it automatically sends the SYN message to the client. Manual SYN: After the server receives the NCK message with the wrong sequence number from the client, it needs to manually check the cause of the message sequence number error and whether the message is lost. After the check is completed, it manually sends SYN to the client.
[0160] The SYN message will resynchronize all sequence numbers (including the message sequence numbers from the server to the client, and the message sequence numbers from the client to the server). The sender of the SYN message sets the "next expected sequence number" to 0001, which means that the sequence number of the next message sent by the receiver of the SYN message must be 0001. The receiver of the SYN message also sets the "next expected sequence number" to 0001, which means that the sequence number of the next message sent by the sender of the SYN message must be 0001. If the receiver of the SYN is not currently in "synchronization error mode", it will still receive and process the SYN message.
[0161] SYN has no message confirmation, that is, when resynchronizing, it is necessary to ensure that the link (connection) with the subsystem (i.e., the system as the client) is fine and the subsystem is ready to receive a SYN message. The SYN message is sent as an unconfirmed message (i.e., in the message structure, "confirmation request flag" == 0, "sequence number" == 0000).
[0162] The following describes the data security and data buffering mechanism of the embodiment of the present invention. In the embodiment of the present invention, each system is responsible for the message data being sent until the receiving end responds to the message, after which the receiving end is responsible, even in special circumstances (such as network failure, system crash, etc.).
[0163] If the communication component (the meaning of the communication component depends on the general software structure on the system) and the data processing component are only loosely coupled, there must be a data buffer in the communication component. If a data processing component generates a message to another system, but it cannot be sent temporarily for some reason (such as the link (connection) is not established and the previous message has not been confirmed), the message must be stored safely at the sending end. If a message arrives and the message cannot currently pass through the communication component to the corresponding data processing component, the communication component needs to store the message in the buffer. This buffer must also be safe. Only when the message is stored can the response be sent back to the sender.
[0164] Based on the above data security and data buffering mechanism, a communication flow diagram of an embodiment of the present invention is as follows: Figure 3 shown.
[0165] At the sending end, the data interaction component submits data to the communication component for transmission (1). After the sending end stores the data in the transmission buffer (2), it only returns an OK signal to the data processing component. The data processing component receives the handshake OK signal (3), and the communication component sends the data to the partner system (i.e., the receiving end) (4). It should be noted that if the data cannot be stored in the transmission buffer (for example, the buffer is full), a NOT OK signal is returned to the data processing component and the data is not sent. There is no particular order for the two steps of returning the OK signal to the data processing component and sending the data to the partner system.
[0166] At the receiving end, the communication component stores the data in the receiving buffer (5) and returns a positive response, i.e., an ACK message (6), to the sending end communication component. Since it may take a considerable time to return a positive response to the sending end communication component, the step of returning an OK signal to the data processing component (3) may be performed first. If the data cannot be stored in the receiving buffer (for example, the buffer is full), an NCK message must be returned to the sending end.
[0167] On the sending side, in response to the received ACK, the communication component automatically performs data deletion from the send buffer (7).
[0168] In addition, at the receiving end, the communication component sends data to the data interaction component (8), the data interaction component submits the returned data (9), and then the communication component aggregates and deletes the cached data from the receiving buffer area (10).
[0169] The above components can also be called modules. For example, the data interaction component at the sending end can be called a data interaction module, which is used to submit data to the communication component (or communication module) for transmission. The other components are similar and will not be described one by one.
[0170] Before receiving the ACK message, the sender must be able to send the data message again under any circumstances (including communication failure, program failure, system crash, etc.). After receiving the ACK message, the sender will not be required to send the message again. Therefore, the data can be deleted.
[0171] After the receiving end sends the ACK message, the message cannot be lost under any circumstances (including communication failure, program failure, system crash, etc.) because the sending end may not be able to resend the message.
[0172] Either system of the communicating parties in the embodiment of the present invention may record all sent and received data, as well as all other events, in a log file to ensure that data analysis can be performed later in unclear situations and necessary actions can be taken to prevent problems from occurring.
[0173] The embodiments of the present invention can well solve the defects of the existing communication scheme between the business party logistics management system and the manufacturer logistics management system in the e-commerce field. The message response mechanism, idempotence processing mechanism (i.e., responding to received duplicate messages as usual), and data retransmission mechanism proposed in the embodiments of the present invention ensure the integrity of business data and the rapid consistency processing of messages. The sequence number synchronization mechanism ensures the fault tolerance of the sequence number and has a rapid self-recovery function. The PLC device needs to be registered after powering on, and can use a variety of methods to perform security verification, including but not limited to TOKEN value verification, IP, port, MAC address verification, link device name verification, message length verification, etc., to ensure the security of message interaction. The heartbeat mechanism ensures the rapid detection of abnormal devices and the effective release of network resources. The embodiments of the present invention also define special data structures, simplify message encoding, increase the density of effective information per byte, and solve the problems of message splitting and unpacking and sticking of TCP connections. The server can receive connections from multiple clients, support multi-threading, improve the processing performance of the device, and reduce development complexity. There is a unique channel between the business system (which can be the server) and the PLC device (which can be the client). There is no need for frequent three-way handshakes, thereby reducing network performance consumption, ensuring stable and reliable communication, and ensuring the sequence and reliability of instructions.
[0174] Figure 4 It is a schematic diagram of the main structure of a communication system according to an embodiment of the present invention.
[0175] like Figure 4 As shown, a communication system 400 according to an embodiment of the present invention includes a client 401 and a server 402, wherein there may be multiple clients 401. The client 401 and the server 402 are partner systems of each other.
[0176] The client 401 establishes a connection with the server 402 based on the TCP / IP information stream interface; after the client 401 successfully establishes a connection with the server 402, messages are transmitted between the client 401 and the server 402 in a preset message structure, wherein, for any end of the client 401 and the server 402, after receiving a confirmation message sent by the partner system of the end, it is determined that the sequence number of the confirmation message is the expected sequence number and the message can be currently processed, and then an affirmative response is sent to the partner system of the end, that is: when the first end of the client 401 and the server 402 sends a confirmation message to the second end, the second end determines that the sequence number of the confirmation message is the expected sequence number and the second end can currently process the message, and then sends an affirmative response to the first end, and after receiving the affirmative response, the first end continues to send subsequent confirmation messages to the second end.
[0177] In one embodiment, in a preset message structure, a message may start with a message start character and end with a message end character, and when the message start character and the message end character are transmitted as message content, the message start character and the message end character in the message content are converted in advance according to conversion rules.
[0178] In one embodiment, the message is transmitted in the form of a data packet, and the size of the data packet sent by the first end is equal to the number of byte streams that can be processed by the second end. When the message is transmitted, it is converted into an ASCII character sequence of a given length, and the content of the message includes: a message start symbol, a confirmation request flag, a sequence number, a destination, a source, a message data application, and a message end symbol.
[0179] In one embodiment, the client 401 and the server 402 are respectively set with their own idle time and connection loss time. When one party does not receive any message from the other party during the idle time, a virtual request message is sent to the other party and the idle time is reset. When any message from the other party is still not received during the reset idle time, the operation of sending the virtual request message to the other party and resetting the idle time is repeated. When any message from the other party is still not received after the set connection loss time, the connection with the other party is disconnected.
[0180] In one embodiment, if the second end is currently unable to process a confirmation message or the sequence number of the confirmation message is not the expected sequence number, a negative response is sent to the first end; if the first end does not receive a positive response or a negative response sent by the second end within a specified time, the confirmation message is resent; when the number of times the confirmation message is resent reaches a preset upper limit and a positive response or a negative response is still not received from the second end, the first end disconnects.
[0181] In one embodiment, the negative acknowledgement includes a first type of negative acknowledgement and a second type of negative acknowledgement; if the sequence number of the confirmation message received by the second end is an incorrect sequence number, the first type of negative acknowledgement is sent to the first end; if the sequence number of the confirmation message received by the second end is an expected sequence number, but the second end is currently unable to process the message, the second type of negative acknowledgement is sent to the first end.
[0182] When the first end receives the second type of negative response from the second end for multiple times in succession, it may wait for a preset time and send a confirmation message again after receiving the second type of negative response each time.
[0183] When the second end receives the first type of negative response, the first end and the second end enter an asynchronous mode. In the asynchronous mode, no messages other than SYN messages are transmitted between the first end and the second end, and the server 402 between the first end and the second end performs the following resynchronization action: the server 402 sets the next expected incoming message sequence number and the next message sequence number to be sent of the server 402 to preset values, and sends a SYN message to the client 401, so that the client 401 also sets the next expected incoming message sequence number and the next message sequence number to be sent of the client 401 to the preset values.
[0184] If the sequence number of the confirmation message received by the second end is the same as the sequence number of the confirmation message received previously, and the second end is currently able to process the message, then a positive response is sent to the first end.
[0185] After the first end in the client 401 and the server 402 sends an unconfirmed message to the second end, if the second end cannot process the unconfirmed message, the unconfirmed message is discarded without notifying the first end.
[0186] In addition, the specific implementation content of the communication system in the embodiment of the present invention has been described in detail in the communication method described above, so the repeated content will not be described again here.
[0187] Figure 5 An exemplary system architecture 500 is shown to which a communication method or a communication system according to an embodiment of the present invention can be applied.
[0188] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0189] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0190] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0191] The server 505 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 501, 502, and 503. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0192] It should be noted that the communication method provided in the embodiment of the present invention is implemented by a server 505 and terminal devices 501, 502, 503. In the communication system provided in the embodiment of the present invention, the client is located in the terminal devices 501, 502, 503, and the server is located in the server 505.
[0193] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0194] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device or server suitable for implementing an embodiment of the present application. Figure 6 The terminal device or server shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0195] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0196] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0197] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present application are executed.
[0198] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0199] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0200] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor. For example, they may be described as: a processor includes a data interaction module, a sending buffer module, and a communication module. The names of these modules do not constitute a limitation on the modules themselves in some cases. For example, the data interaction module may also be described as a "module for submitting data to a communication component (or communication module) for transmission."
[0201] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: establishing a connection with a partner system based on a TCP / IP information stream interface; after successfully establishing the connection, transmitting messages with the partner system in a preset message structure, wherein, after receiving a confirmation message sent by the partner system, determining that the sequence number of the confirmation message sent by the partner system is the expected sequence number and that the confirmation message sent by the partner system can be processed at present, and then sending a positive response to the partner system.
[0202] According to the technical solution of the embodiment of the present invention, a connection is established with the partner system based on the TCP / IP information flow interface; after the connection is successfully established, a message is transmitted with the partner system in a preset message structure, wherein, after receiving the confirmation message sent by the partner system, it is determined that the sequence number of the confirmation message sent by the partner system is the expected sequence number and the confirmation message sent by the partner system can be processed at present, and then an affirmative response is sent to the partner system. It can ensure data integrity and fast consistency processing, has good fault tolerance, has a fast self-recovery function, simplifies message encoding, improves the density of effective information per unit byte, can quickly detect abnormal devices, effectively release network resources, avoid repeated connections to consume network performance, stable and reliable communication, ensure the order and reliability of instructions, high message interaction security, support multi-threading, reduce development complexity, and avoid unpacking and sticking packages.
[0203] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A communication method, characterized in that: include: Establish connection with partner system based on TCP / IP information flow interface; After the connection is successfully established, a message is transmitted with the partner system in a preset message structure, wherein, after receiving a confirmation message sent by the partner system, it is determined that the sequence number of the confirmation message sent by the partner system is an expected sequence number and the confirmation message sent by the partner system can be currently processed, and then a positive response is sent to the partner system; If the sequence number of the confirmation message received from the partner system is an incorrect sequence number, a first type negative response is sent to the partner system; the method is performed by a server or a client; after sending the first type negative response to the partner system, an asynchronous mode is entered with the partner system, in which no message other than a sequence number synchronization message is transmitted with the partner system, and, In the case where the method is performed by the server, the server performs the following resynchronization actions: the server sets the next expected incoming message sequence number and the next message sequence number to be sent of the server to preset values, and sends the sequence number synchronization message to the partner system, so that the partner system also sets the next expected incoming message sequence number and the next message sequence number to be sent of the partner system to the preset values; When the method is executed by the client, the sequence number synchronization message sent by the partner system is received, so as to set the next expected incoming message sequence number and the next message sequence number to be sent to the preset value according to the sequence number synchronization message sent by the partner system.
2. The method according to claim 1, characterized in that In the preset message structure, the message starts with a message start character and ends with a message end character, and when the message start character and the message end character are transmitted as message content, the message start character and the message end character in the message content are converted into characters in advance according to the conversion rules.
3. The method according to claim 1 or 2, characterized in that: The message is transmitted in the form of a data packet, and the size of the data packet is equal to the number of processable byte streams.
4. The method according to claim 2, characterized in that: The message is converted into an ASCII character sequence of a given length when transmitted, and the content of the message includes: a message start symbol, a confirmation request flag, a sequence number, a destination, a source, a message data application, and a message end symbol.
5. The method according to claim 1, characterized in that It also includes pre-setting of idle time and connection loss time; When no message from the partner system is received within the idle time, a virtual request message is sent to the partner system and the idle time is reset. When any message from the partner system is still not received within the reset idle time, the operation of sending the virtual request message to the partner system and resetting the idle time is repeated. When any message from the partner system is still not received after the set connection loss time, the connection with the partner system is disconnected.
6. The method according to claim 1, characterized in that If the confirmation message sent by the partner system cannot be processed currently or the sequence number of the confirmation message sent by the partner system is not the expected sequence number, a negative response is sent to the partner system; the negative response sent to the partner system includes a first type negative response and a second type negative response; If the sequence number of the received confirmation message from the partner system is an expected sequence number, but the confirmation message from the partner system cannot be processed currently, the second type negative response is sent to the partner system.
7. The method according to claim 6, characterized in that Also includes: Sending a confirmation message to the partner system, and waiting for the partner system to send a positive response or a negative response; If no positive or negative response is received from the partner system within a specified time, resending a confirmation message to the partner system, and if no positive or negative response is received from the partner system after the number of resending confirmation messages reaches a preset upper limit, disconnecting from the partner system; the negative response sent by the partner system includes the first type of negative response and the second type of negative response; If the second type of negative response sent by the partner system is received multiple times in succession, after each time the second type of negative response from the partner system is received, a preset time is waited and a confirmation message is sent to the partner system again.
8. The method according to claim 6 or 1, characterized in that: If the sequence number of the received confirmation message of the partner system is repeated with the sequence number of the previously received confirmation message, and the confirmation message of the partner system can be processed currently, the positive response is sent to the partner system.
9. The method according to claim 1, characterized in that: After receiving the unconfirmed message sent by the partner system, if the unconfirmed message cannot be processed, the unconfirmed message is discarded without notifying the partner system.
10. A communication system, characterized in that: include: The client and server of the partner system, where: The client establishes a connection with the server based on a TCP / IP information stream interface; After the client successfully establishes a connection with the server, the client and the server transmit messages in a preset message structure, wherein, for any one of the client and the server, after receiving a confirmation message sent by the partner system of the end, it is determined that the sequence number of the confirmation message is the expected sequence number and the message can be processed currently, and then a positive response is sent to the partner system of the end; If the sequence number of the confirmation message received from the partner system is an incorrect sequence number, a first type negative acknowledgement is sent to the partner system; after the first type negative acknowledgement is sent to the partner system, an asynchronous mode is entered with the partner system, in which no message other than the sequence number synchronization message is transmitted with the partner system, and, In the case where either end is a server, the server performs the following resynchronization action: the server sets the next expected incoming message sequence number and the next message sequence number to be sent of the server to preset values, and sends the sequence number synchronization message to the partner system, so that the partner system also sets the next expected incoming message sequence number and the next message sequence number to be sent of the partner system to the preset values; In the case that either end is a client, the sequence number synchronization message sent by the partner system is received, so as to set the next expected incoming message sequence number and the next message sequence number to be sent to the preset value according to the sequence number synchronization message sent by the partner system.
11. An electronic device, characterized in that: include: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the method according to any one of claims 1 to 9.
12. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Data stream message transmission control method and device
CN101841468A
Server communication method based on TCP / IP protocol
CN110958264A