[go: up one dir, main page]

CN116614485A - Communication method, device and electronic equipment between client and server - Google Patents

Communication method, device and electronic equipment between client and server Download PDF

Info

Publication number
CN116614485A
CN116614485A CN202210123000.5A CN202210123000A CN116614485A CN 116614485 A CN116614485 A CN 116614485A CN 202210123000 A CN202210123000 A CN 202210123000A CN 116614485 A CN116614485 A CN 116614485A
Authority
CN
China
Prior art keywords
client
server
storage address
data
response message
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210123000.5A
Other languages
Chinese (zh)
Inventor
刘羽
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Shizhen Information Technology Co Ltd
Original Assignee
Guangzhou Shizhen Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Shizhen Information Technology Co Ltd filed Critical Guangzhou Shizhen Information Technology Co Ltd
Priority to CN202210123000.5A priority Critical patent/CN116614485A/en
Publication of CN116614485A publication Critical patent/CN116614485A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

本申请公开了一种客户端和服务端间的通信方法、装置和电子设备。其中,该方法包括:获取数据库中当前更新周期内更新的数据以及数据对应的存储地址;将存储地址发送给客户端,其中,存储地址中携带有同步序列标识,同步序列标识用于表示服务端发送的请求消息;在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作;在数据重传次数达到预设阈值,且在预设超时时间段内未接收到客户端发送的响应消息的情况下,将存储地址所存储的数据记录到异常数据库中,并提示客户端发生异常。本申请解决了服务端和客户端之间建立长连接时无法保证消息的可靠性和一致性的技术问题。

The application discloses a communication method, device and electronic equipment between a client and a server. Among them, the method includes: obtaining the data updated in the current update cycle in the database and the storage address corresponding to the data; sending the storage address to the client, wherein the storage address carries a synchronization sequence identifier, which is used to indicate that the server The request message sent; when the response message sent by the client is not received within the preset timeout period, the operation of retransmitting the data overtime is performed; when the number of data retransmissions reaches the preset threshold and there is no When the response message sent by the client is received, the data stored in the storage address is recorded in the exception database, and the client is prompted that an exception occurs. This application solves the technical problem that the reliability and consistency of messages cannot be guaranteed when a long connection is established between the server and the client.

Description

客户端和服务端间的通信方法、装置和电子设备Communication method, device and electronic equipment between client and server

技术领域technical field

本申请涉及数据通信领域,具体而言,涉及一种客户端和服务端间的通信方法、装置和电子设备。The present application relates to the field of data communication, in particular, to a communication method, device and electronic equipment between a client and a server.

背景技术Background technique

当用户在后台操作数据的时候,服务器需要将某些变更的数据及时通知给客户端(公司的一系列产品,如交互大板、画屏、数字标牌等),但服务器没办法主动请求客户端,因此往往需要在服务器和客户端之间建立长连接,如何保证长连接的稳定性,以及消息的可靠性和一致性,则是值的考虑的事情。When the user is operating data in the background, the server needs to notify the client of some changed data in a timely manner (a series of products of the company, such as interactive large boards, picture screens, digital signage, etc.), but the server has no way to actively request the client. Therefore, it is often necessary to establish a long connection between the server and the client. How to ensure the stability of the long connection, as well as the reliability and consistency of the message, is a matter of value.

对于消息可靠性,也就是我们需要保证服务器发出的请求能被客户端收到,假设因为网络原因请求实在无法到达客户端,也需要有兜底机制保证用户可以获知该情况。For message reliability, that is, we need to ensure that the request sent by the server can be received by the client. If the request cannot reach the client due to network reasons, we also need a mechanism to ensure that the user can know the situation.

对于一致性,基于云屏的实际业务,大板客户端对比服务器更加不稳定,会因为各种现实因素而更加频繁地关机(正常和异常)。为此我们需要提供一种机制,让客户端能够在恢复到网络正常后,能确保数据的一致性。For consistency, based on the actual business of the cloud screen, the large board client is more unstable than the server, and will shut down more frequently (normal and abnormal) due to various practical factors. To this end, we need to provide a mechanism that allows the client to ensure data consistency after the network returns to normal.

针对上述的问题,目前尚未提出有效的解决方案。For the above problems, no effective solution has been proposed yet.

发明内容Contents of the invention

本申请实施例提供了一种客户端和服务端间的通信方法、装置和电子设备,以至少解决服务端和客户端之间建立长连接时无法保证消息的可靠性和一致性的技术问题。Embodiments of the present application provide a communication method, device, and electronic device between a client and a server, so as to at least solve the technical problem that the reliability and consistency of messages cannot be guaranteed when a long connection is established between the server and the client.

根据本申请实施例的一个方面,提供了一种客户端和服务端间的通信方法,包括:获取数据库中当前更新周期内更新的数据以及数据对应的存储地址;将存储地址发送给客户端,其中,存储地址中携带有同步序列标识,同步序列标识用于表示服务端发送的请求消息;在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作,其中,响应消息为对与存储地址和同步序列标识所对应的数据重传结果的响应;在数据重传次数达到预设阈值,且在预设超时时间段内未接收到客户端发送的响应消息的情况下,将存储地址所存储的数据记录到异常数据库中,并提示客户端发生异常。According to an aspect of the embodiment of the present application, a communication method between a client and a server is provided, including: acquiring data updated in the current update period in the database and a storage address corresponding to the data; sending the storage address to the client, Among them, the storage address carries a synchronization sequence identifier, and the synchronization sequence identifier is used to represent the request message sent by the server; when the response message sent by the client is not received within the preset timeout period, the operation of retransmitting the data overtime is performed, Wherein, the response message is a response to the data retransmission result corresponding to the storage address and the synchronization sequence identifier; when the number of data retransmissions reaches the preset threshold and the response message sent by the client is not received within the preset timeout period In the case of , record the data stored in the storage address into the exception database, and prompt the client that an exception has occurred.

可选地,将存储地址发送给客户端之前,方法还包括:接收客户端发送的安全套接字websocket连接请求;将客户端和服务端成功建立连接的消息发送给客户端。Optionally, before sending the storage address to the client, the method further includes: receiving a secure socket websocket connection request sent by the client; and sending a message that the client and the server successfully establish a connection to the client.

可选地,websocket连接请求中携带有客户端的标识信息;方法还包括:在客户端和服务端成功建立连接后将客户端的标识信息存储到服务端中。Optionally, the websocket connection request carries the identification information of the client; the method further includes: storing the identification information of the client in the server after the connection between the client and the server is successfully established.

可选地,同步序列标识包括:将客户端的标识信息和时间戳进行编码后得到的字符串。Optionally, the synchronization sequence identification includes: a character string obtained by encoding the identification information of the client and the time stamp.

可选地,响应消息与同步序列标识一致,预设超时时间段依据客户端缓存数据对应的存储地址的时间、存储地址和同步序列标识在客户端和服务端的往返时间、冗余时间确定的。Optionally, the response message is consistent with the synchronization sequence identifier, and the preset timeout period is determined according to the storage address corresponding to the client cache data, the round-trip time between the storage address and the synchronization sequence identifier between the client and the server, and the redundancy time.

可选地,方法还包括:在预设超时时间段内接收到客户端发送的响应消息时,控制服务端进入空闲状态。Optionally, the method further includes: controlling the server to enter an idle state when receiving a response message sent by the client within a preset timeout period.

根据本申请实施例的另一方面,还提供了一种客户端和服务端间的通信方法,包括:确定客户端的网络状态;在客户端的网络状态为正常时,向服务端发送安全套接字websocket连接请求;接收服务端发送的客户端和服务端成功建立连接的消息,以及接收服务端发送的与当前更新周期内更新的数据对应的存储地址,其中,存储地址中携带有同步序列标识,同步序列标识用于表示服务端发送的请求消息,更新的数据存储在数据库中;将与存储地址和同步序列标识对应的响应消息发送给服务端。According to another aspect of the embodiment of the present application, there is also provided a communication method between a client and a server, including: determining the network status of the client; when the network status of the client is normal, sending a secure socket to the server websocket connection request; receive the message sent by the server that the client and the server have successfully established a connection, and receive the storage address corresponding to the data updated in the current update cycle sent by the server, where the storage address carries a synchronization sequence identifier, The synchronization sequence identifier is used to represent the request message sent by the server, and the updated data is stored in the database; the response message corresponding to the storage address and the synchronization sequence identifier is sent to the server.

可选地,接收服务端发送的与当前更新周期内更新的数据对应的存储地址之后,方法还包括:将存储地址缓存到本地。Optionally, after receiving the storage address sent by the server and corresponding to the updated data in the current update cycle, the method further includes: caching the storage address locally.

可选地,方法还包括:在接收到服务端多次发送的相同存储地址的请求消息时,将最后一次接收到的请求消息中的存储地址缓存到本地,并将最后一次接收到的请求消息的响应消息发送给服务端;在接收到服务端多次发送的不同存储地址的请求消息时,将最后一次接收到的请求消息中的存储地址缓存到本地,并将最后一次接收到的请求消息的响应消息发送给服务端。Optionally, the method further includes: when receiving request messages of the same storage address sent by the server multiple times, caching the storage address in the last received request message locally, and storing the last received request message The response message sent to the server; when receiving the request message of different storage addresses sent by the server multiple times, the storage address in the last received request message is cached locally, and the last received request message The response message is sent to the server.

可选地,将与存储地址和同步序列标识对应的响应消息发送给服务端之后,方法还包括:依据存储地址请求数据库中与存储地址对应的数据;接收数据库返回的与存储地址对应的数据。Optionally, after sending the response message corresponding to the storage address and the synchronization sequence identifier to the server, the method further includes: requesting data corresponding to the storage address in the database according to the storage address; receiving data corresponding to the storage address returned by the database.

根据本申请实施例的再一方面,还提供了一种客户端和服务端间的通信装置,包括:获取模块,用于获取数据库中当前更新周期内更新的数据以及数据对应的存储地址;发送模块,用于将存储地址发送给客户端,其中,存储地址中携带有同步序列标识,同步序列标识用于表示服务端发送的请求消息;处理模块,用于在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作,其中,响应消息为对与存储地址和同步序列标识所对应的数据重传结果的响应;提示模块,用于在数据重传次数达到预设阈值,且在预设超时时间段内未接收到客户端发送的响应消息的情况下,将存储地址所存储的数据记录到异常数据库中,并提示客户端发生异常。According to still another aspect of the embodiment of the present application, there is also provided a communication device between the client and the server, including: an acquisition module, configured to acquire the data updated in the current update period in the database and the storage address corresponding to the data; The module is used to send the storage address to the client, wherein the storage address carries a synchronization sequence identifier, and the synchronization sequence identifier is used to represent the request message sent by the server; the processing module is used to receive the request message within the preset timeout period When the response message sent by the client is received, the operation of retransmitting the data overtime is performed, wherein the response message is a response to the data retransmission result corresponding to the storage address and the synchronization sequence identifier; the prompt module is used to check the data retransmission times When the preset threshold is reached and the response message sent by the client is not received within the preset timeout period, the data stored in the storage address is recorded in the exception database, and the client is notified of an exception.

根据本申请实施例的再一方面,还提供了一种电子设备,包括:存储器,用于存储程序指令;处理器,与存储器连接,用于执行实现以下功能的程序指令:获取数据库中当前更新周期内更新的数据以及数据对应的存储地址;将存储地址发送给客户端,其中,存储地址中携带有同步序列标识,同步序列标识用于表示服务端发送的请求消息;在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作,其中,响应消息为对与存储地址和同步序列标识所对应的数据重传结果的响应;在数据重传次数达到预设阈值,且在预设超时时间段内未接收到客户端发送的响应消息的情况下,将存储地址所存储的数据记录到异常数据库中,并提示客户端发生异常。According to yet another aspect of the embodiments of the present application, there is also provided an electronic device, including: a memory, used to store program instructions; a processor, connected to the memory, used to execute the program instructions to realize the following functions: obtain the current update in the database The data updated in the period and the storage address corresponding to the data; the storage address is sent to the client, where the storage address carries a synchronization sequence identifier, which is used to represent the request message sent by the server; within the preset timeout period When the response message sent by the client is not received within a period of time, the operation of retransmitting the data overtime is performed, wherein the response message is the response to the data retransmission result corresponding to the storage address and the synchronization sequence identifier; A threshold is set, and if no response message is received from the client within the preset timeout period, the data stored in the storage address is recorded in the exception database, and the client is prompted for an exception.

根据本申请实施例的再一方面,还提供了一种非易失性存储介质,该非易失性存储介质包括存储的程序,其中,在程序运行时控制该非易失性存储介质所在设备执行上述客户端和服务端间的通信方法。According to still another aspect of the embodiments of the present application, there is also provided a non-volatile storage medium, the non-volatile storage medium includes a stored program, wherein, when the program is running, the device where the non-volatile storage medium is located is controlled Execute the above communication method between the client and the server.

在本申请实施例中,通过获取数据库中当前更新周期内更新的数据以及数据对应的存储地址,将存储地址发送给客户端,其中,存储地址中携带有同步序列标识,在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作,在数据重传次数达到预设阈值,且在预设超时时间段内未接收到客户端发送的响应消息的情况下,将存储地址所存储的数据记录到异常数据库中,并提示客户端发生异常,达到了依据数据超时重传保证数据的可靠性传输的目的,实现了将更新的数据及时通知客户端以确保数据一致性的技术效果,进而解决了服务端和客户端之间建立长连接时无法保证消息的可靠性和一致性的技术问题。In this embodiment of the application, the storage address is sent to the client by obtaining the data updated in the current update cycle in the database and the storage address corresponding to the data, wherein the storage address carries a synchronization sequence identifier, and the storage address is stored within the preset timeout period. When the response message sent by the client is not received within a period of time, the operation of retransmitting the data overtime is performed. When the number of data retransmissions reaches the preset threshold and the response message sent by the client is not received within the preset timeout period , the data stored in the storage address is recorded in the exception database, and the client is prompted for an exception, which achieves the purpose of ensuring the reliability of data transmission based on data timeout retransmission, and realizes the timely notification of updated data to the client to ensure data The technical effect of consistency further solves the technical problem that the reliability and consistency of messages cannot be guaranteed when a long connection is established between the server and the client.

附图说明Description of drawings

此处所说明的附图用来提供对本申请的进一步理解,构成本申请的一部分,本申请的示意性实施例及其说明用于解释本申请,并不构成对本申请的不当限定。在附图中:The drawings described here are used to provide a further understanding of the application and constitute a part of the application. The schematic embodiments and descriptions of the application are used to explain the application and do not constitute an improper limitation to the application. In the attached picture:

图1是根据本申请实施例的一种用于实现客户端和服务端间的通信方法的计算机终端(或电子设备)的硬件结构框图;FIG. 1 is a block diagram of a hardware structure of a computer terminal (or electronic device) for implementing a communication method between a client and a server according to an embodiment of the present application;

图2是根据本申请实施例的一种客户端和服务端间的通信方法的流程图;FIG. 2 is a flowchart of a communication method between a client and a server according to an embodiment of the present application;

图3是根据本申请实施例的一种建立websocket连接的流程图;Fig. 3 is a kind of flowchart of establishing websocket connection according to the embodiment of the present application;

图4a是根据本申请实施例的一种客户端和服务端间的消息传输的示意图;FIG. 4a is a schematic diagram of message transmission between a client and a server according to an embodiment of the present application;

图4b是根据本申请实施例的一种数据超时重传的示意图;FIG. 4b is a schematic diagram of data timeout retransmission according to an embodiment of the present application;

图5是根据本申请实施例的第一种客户端获取更新的数据包的流程图;FIG. 5 is a flow chart of a first type of client acquiring an updated data packet according to an embodiment of the present application;

图6是根据本申请实施例的第二种客户端获取更新的数据包的流程图;FIG. 6 is a flow chart of obtaining an updated data packet by a second client according to an embodiment of the present application;

图7是根据本申请实施例的另一种客户端和服务端间的通信方法的流程图;FIG. 7 is a flowchart of another communication method between a client and a server according to an embodiment of the present application;

图8是根据本申请实施例的一种请求数据的流程图;Fig. 8 is a flow chart of requesting data according to an embodiment of the present application;

图9是根据本申请实施例的又一种客户端和服务端间的通信方法的流程图;FIG. 9 is a flowchart of another communication method between a client and a server according to an embodiment of the present application;

图10是根据本申请实施例的一种客户端和服务端间的通信装置的结构图。Fig. 10 is a structural diagram of a communication device between a client and a server according to an embodiment of the present application.

具体实施方式Detailed ways

为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分的实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本申请保护的范围。In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiment of the application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiment of the application. Obviously, the described embodiment is only It is an embodiment of a part of the application, but not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by persons of ordinary skill in the art without creative efforts shall fall within the scope of protection of this application.

需要说明的是,本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。It should be noted that the terms "first" and "second" in the description and claims of the present application and the above drawings are used to distinguish similar objects, but not necessarily used to describe a specific sequence or sequence. It is to be understood that the data so used are interchangeable under appropriate circumstances such that the embodiments of the application described herein can be practiced in sequences other than those illustrated or described herein. Furthermore, the terms "comprising" and "having", as well as any variations thereof, are intended to cover a non-exclusive inclusion, for example, a process, method, system, product or device comprising a sequence of steps or elements is not necessarily limited to the expressly listed instead, may include other steps or elements not explicitly listed or inherent to the process, method, product or apparatus.

首先,在对本申请实施例进行描述的过程中出现的部分名词或术语适用于如下解释:First of all, some nouns or terms that appear during the description of the embodiments of the present application are applicable to the following explanations:

同步序列标识:即syn号,由客户端的标识信息和时间戳,经过base64编码得到的字符串,任意服务端在任意时刻发送的请求均不同,客户端的标识信息在客户端和服务端建立websocket连接时存入服务端中。Synchronization sequence identification: the syn number, the string obtained by base64 encoding of the identification information and timestamp of the client, the request sent by any server at any time is different, and the identification information of the client establishes a websocket connection between the client and the server stored in the server.

响应消息:即ack号,与syn号一致,用于通知服务端,客户端已经接收到服务端发送的请求消息。Response message: the ack number, which is consistent with the syn number, is used to notify the server that the client has received the request message sent by the server.

超时重传:服务端没有接收到客户端发送的ack,在预设超时时间段内会重传多次,该预设超时时间段即最小超时时间。最小超时时间=客户端的缓存数据的时间+客户端和服务端之间的RTT时间(数据包的往返时间)+冗余时间,重传次数没有标准,重传之后需要重新计算超时时间,其中,冗余时间是指在系统发生偶发性错误时,利用时间的持续特性,重复执行发生错误的系统过程,来消除错误的一种容错思想。Timeout retransmission: The server does not receive the ack sent by the client, and will retransmit multiple times within the preset timeout period, which is the minimum timeout period. The minimum timeout time = the time of the client's cached data + the RTT time between the client and the server (the round-trip time of the data packet) + redundancy time, there is no standard for the number of retransmissions, and the timeout time needs to be recalculated after retransmission, among them, Redundant time refers to a fault-tolerant idea that uses the continuous characteristics of time to repeatedly execute the system process in which errors occur to eliminate errors when sporadic errors occur in the system.

数据缓存:客户端接收到服务端发送的数据之后将其暂存到本地。Data cache: After the client receives the data sent by the server, it temporarily stores it locally.

根据本申请实施例,提供了一种客户端和服务端间的通信方法实施例,需要说明的是,在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行,并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。According to an embodiment of the present application, an embodiment of a communication method between a client and a server is provided. It should be noted that the steps shown in the flow chart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions and, although a logical order is shown in the flowcharts, in some cases the steps shown or described may be performed in an order different from that shown or described herein.

本申请实施例所提供的客户端和服务端间的通信方法实施例可以在移动终端、计算机终端或者类似的运算装置中执行。图1示出了一种用于实现客户端和服务端间的通信方法的计算机终端(或电子设备)的硬件结构框图。如图1所示,计算机终端10(或电子设备10)可以包括一个或多个(图中采用102a、102b,……,102n来示出)处理器(处理器可以包括但不限于微处理器MCU或可编程逻辑器件FPGA等的处理装置)、用于存储数据的存储器104、以及用于通信功能的传输模块106。除此以外,还可以包括:显示器、输入/输出接口(I/O接口)、通用串行总线(USB)端口(可以作为I/O接口的端口中的一个端口被包括)、网络接口、电源和/或相机。本领域普通技术人员可以理解,图1所示的结构仅为示意,其并不对上述电子装置的结构造成限定。例如,计算机终端10还可包括比图1中所示更多或者更少的组件,或者具有与图1所示不同的配置。The embodiment of the communication method between the client and the server provided in the embodiment of the present application may be executed in a mobile terminal, a computer terminal or a similar computing device. FIG. 1 shows a block diagram of a hardware structure of a computer terminal (or electronic device) for implementing a communication method between a client and a server. As shown in Figure 1, the computer terminal 10 (or electronic device 10) may include one or more (shown by 102a, 102b, ..., 102n in the figure) processors (processors may include but not limited to microprocessors) MCU or a processing device such as a programmable logic device FPGA), a memory 104 for storing data, and a transmission module 106 for communication functions. In addition, it can also include: a display, an input/output interface (I/O interface), a universal serial bus (USB) port (which can be included as one of the ports of the I/O interface), a network interface, a power supply and/or camera. Those of ordinary skill in the art can understand that the structure shown in FIG. 1 is only a schematic diagram, and it does not limit the structure of the above-mentioned electronic device. For example, computer terminal 10 may also include more or fewer components than shown in FIG. 1 , or have a different configuration than that shown in FIG. 1 .

应当注意到的是上述一个或多个处理器和/或其他数据处理电路在本文中通常可以被称为“数据处理电路”。该数据处理电路可以全部或部分的体现为软件、硬件、固件或其他任意组合。此外,数据处理电路可为单个独立的处理模块,或全部或部分的结合到计算机终端10(或电子设备)中的其他元件中的任意一个内。如本申请实施例中所涉及到的,该数据处理电路作为一种处理器控制(例如与接口连接的可变电阻终端路径的选择)。It should be noted that the one or more processors and/or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuit may be implemented in whole or in part as software, hardware, firmware or other arbitrary combinations. In addition, the data processing circuit can be a single independent processing module, or be fully or partially integrated into any of the other elements in the computer terminal 10 (or electronic equipment). As mentioned in the embodiment of the present application, the data processing circuit is used as a processor control (for example, the selection of the terminal path of the variable resistor connected to the interface).

存储器104可用于存储应用软件的软件程序以及模块,如本申请实施例中的客户端和服务端间的通信方法对应的程序指令/数据存储装置,处理器通过运行存储在存储器104内的软件程序以及模块,从而执行各种功能应用以及数据处理,即实现上述的客户端和服务端间的通信方法。存储器104可包括高速随机存储器,还可包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器104可进一步包括相对于处理器远程设置的存储器,这些远程存储器可以通过网络连接至计算机终端10。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。The memory 104 can be used to store software programs and modules of application software, such as the program instruction/data storage device corresponding to the communication method between the client and the server in the embodiment of the present application, and the processor runs the software program stored in the memory 104 And modules, so as to execute various functional applications and data processing, that is, to realize the above-mentioned communication method between the client and the server. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory that is remotely located relative to the processor, and these remote memories may be connected to the computer terminal 10 through a network. Examples of the aforementioned networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

传输模块106用于经由一个网络接收或者发送数据。上述的网络具体实例可包括计算机终端10的通信供应商提供的无线网络。在一个实例中,传输装置106包括一个网络适配器(Network Interface Controller,NIC),其可通过基站与其他网络设备相连从而可与互联网进行通讯。在一个实例中,传输装置106可以为射频(Radio Frequency,RF)模块,其用于通过无线方式与互联网进行通讯。The transmission module 106 is used to receive or send data via a network. The specific example of the above-mentioned network may include a wireless network provided by the communication provider of the computer terminal 10 . In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet in a wireless manner.

显示器可以例如触摸屏式的液晶显示器(LCD),该液晶显示器可使得用户能够与计算机终端10(或电子设备)的用户界面进行交互。The display may be, for example, a touchscreen liquid crystal display (LCD), which may enable a user to interact with the user interface of the computer terminal 10 (or electronic device).

此处需要说明的是,在一些可选实施例中,上述图1所示的计算机设备(或电子设备)可以包括硬件元件(包括电路)、软件元件(包括存储在计算机可读介质上的计算机代码)、或硬件元件和软件元件两者的结合。应当指出的是,图1仅为特定具体实例的一个实例,并且旨在示出可存在于上述计算机设备(或电子设备)中的部件的类型。It should be noted here that, in some optional embodiments, the computer equipment (or electronic equipment) shown in FIG. 1 may include hardware components (including circuits), software components (including computer code), or a combination of both hardware and software elements. It should be noted that FIG. 1 is only one example of a particular embodiment, and is intended to illustrate the types of components that may be present in the computer device (or electronic device) described above.

在上述运行环境下,本申请实施例提供了如图2所示的客户端和服务端间的通信方法。图2是根据本申请实施例的一种客户端和服务端间的通信方法的流程图,如图2所示,该方法包括如下步骤:In the above operating environment, the embodiment of the present application provides a communication method between the client and the server as shown in FIG. 2 . Fig. 2 is a flowchart of a communication method between a client and a server according to an embodiment of the present application. As shown in Fig. 2, the method includes the following steps:

步骤S202,获取数据库中当前更新周期内更新的数据以及数据对应的存储地址;Step S202, acquiring the data updated in the current update period in the database and the storage address corresponding to the data;

步骤S204,将存储地址发送给客户端,其中,存储地址中携带有同步序列标识,同步序列标识用于表示服务端发送的请求消息;Step S204, sending the storage address to the client, wherein the storage address carries a synchronization sequence identifier, and the synchronization sequence identifier is used to represent the request message sent by the server;

步骤S206,在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作,其中,响应消息为对与存储地址和同步序列标识所对应的数据重传结果的响应;Step S206, when the response message sent by the client is not received within the preset timeout period, the operation of retransmitting the data overtime is performed, wherein the response message is the result of retransmission of the data corresponding to the storage address and the synchronization sequence identifier response;

步骤S208,在数据重传次数达到预设阈值,且在预设超时时间段内未接收到客户端发送的响应消息的情况下,将存储地址所存储的数据记录到异常数据库中,并提示客户端发生异常。Step S208, when the number of data retransmissions reaches the preset threshold and the response message sent by the client is not received within the preset timeout period, record the data stored in the storage address into the exception database, and prompt the client An exception occurred on the terminal.

在本申请实施例中,设置有最大重传次数,该最大重传次数对应数据重传次数的预设阈值。在最大重传次数中,经过预设超时时间段仍未收到客户端发送的响应消息,则提示客户端发生异常。In the embodiment of the present application, a maximum number of retransmissions is set, and the maximum number of retransmissions corresponds to a preset threshold of the number of data retransmissions. In the maximum number of retransmissions, if the response message sent by the client is not received after the preset timeout period, the client will be prompted that an exception has occurred.

在该客户端和服务端间的通信方法中的步骤S204,将存储地址发送给客户端之前,如图3所示的流程图,具体还包括如下步骤:In step S204 in the communication method between the client and the server, before the storage address is sent to the client, the flow chart shown in Figure 3 specifically includes the following steps:

步骤S302,接收客户端发送的安全套接字websocket连接请求;Step S302, receiving the secure socket websocket connection request sent by the client;

步骤S304,将客户端和服务端成功建立连接的消息发送给客户端。Step S304, sending a message that the connection between the client and the server is successfully established to the client.

在步骤S302至步骤S304中,服务端和客户端成功传输数据的前提是,客户端和服务端已经建立了websocket通信连接,因此,在客户端网络正常的情况下,客户端会主动向服务端发起websocket连接请求,服务端接收客户端发送的连接请求后,建立与客户端间的websocket连接通道,并将成功建立websocket连接的消息告知客户端。In step S302 to step S304, the prerequisite for successful data transmission between the server and the client is that the client and the server have established a websocket communication connection. Initiate a websocket connection request. After receiving the connection request sent by the client, the server establishes a websocket connection channel with the client and informs the client of the successful establishment of the websocket connection.

在上述步骤S302中,websocket连接请求中携带有客户端的标识信息,该方法在客户端和服务端成功建立连接后将客户端的标识信息存储到服务端中,该客户端的标识信息具有唯一性,即不同的客户端对应的标识信息不同。In the above step S302, the websocket connection request carries the identification information of the client. After the client and the server successfully establish a connection, the method stores the identification information of the client in the server. The identification information of the client is unique, that is, Different clients correspond to different identification information.

在该客户端和服务端间的通信方法中的步骤S204中,同步序列标识包括:将客户端的标识信息和时间戳进行base64编码后得到的字符串,即syn号。In the step S204 of the communication method between the client and the server, the synchronization sequence identification includes: a character string obtained by base64 encoding the identification information of the client and the time stamp, that is, the syn number.

在该客户端和服务端间的通信方法中的步骤S206中,响应消息与同步序列标识一致,预设超时时间段依据客户端缓存数据对应的存储地址的时间、存储地址和同步序列标识在客户端和服务端的往返时间、冗余时间确定的。In step S206 in the communication method between the client and the server, the response message is consistent with the synchronization sequence identifier, and the preset timeout period is based on the time of the storage address corresponding to the client cache data, the storage address and the synchronization sequence identifier in the client. The round-trip time and redundancy time between the client and the server are determined.

需要说明的是,在服务端发送更新的数据对应的存储地址给客户端后,假设存在网络问题的情况下,服务端不能直接报错,即服务端不能直接通过捕获异常后提示客户端,原因如下:假设服务端发送的存储地址对应的数据包到达客户端后,客户端可能因为各种未知原因而无法处理,即无法及时发送响应消息给服务端。在这种情况下,如果认为服务端只保证数据包到达,则客户端需要依赖更加复杂的机制,以便在客户端恢复网络和机制正常的情况下进行数据的拉取和更新操作。而如果客户端能缓存下来服务端发送的数据包,则客户端只需要不断轮询本地数据并做进一步处理即可。而客户端暂时无法处理请求的这种情况并不属于ws(websocket)的异常,如果服务端没有接收到客户端发送的响应消息(即ack),服务端不可感知到这种异常情况,则会导致服务端无法处理。因此,当数据包到达客户端后,需要客户端回传一个响应消息作保证,同时,响应消息必须在客户端对服务端发送的数据包做了持久化处理后再回传,即客户端先缓存数据包,再回传响应消息。It should be noted that after the server sends the storage address corresponding to the updated data to the client, assuming that there is a network problem, the server cannot directly report an error, that is, the server cannot directly prompt the client after catching the exception. The reasons are as follows : Assume that after the data packet corresponding to the storage address sent by the server reaches the client, the client may not be able to process it due to various unknown reasons, that is, it cannot send a response message to the server in time. In this case, if the server only guarantees the arrival of data packets, the client needs to rely on a more complex mechanism to pull and update data when the client restores the network and the mechanism is normal. And if the client can cache the data packets sent by the server, the client only needs to continuously poll the local data and do further processing. The fact that the client cannot process the request temporarily does not belong to the exception of ws (websocket). If the server does not receive the response message (ie ack) sent by the client, the server cannot perceive this abnormal situation, and it will The server cannot handle it. Therefore, when the data packet arrives at the client, the client needs to return a response message as a guarantee. At the same time, the response message must be sent back after the client performs persistent processing on the data packet sent by the server. Cache the data packet, and then return the response message.

在该客户端和服务端间的通信方法中,在预设超时时间段内接收到客户端发送的响应消息时,控制服务端进入空闲状态。在步骤S206中,若在预设超时时间段内未接收到客户端发送的响应消息时,需进行数据重传的操作,不能在一次预设超时时间段内未接收到响应消息就报错,这是因为响应消息是在客户端做持久化处理之后回传的,客户端处理速度以及网络速度可能存在不稳定的情况,因此客户端的响应消息到达服务端的时间有一定的波动,如果短时间内收不到响应消息就判定数据包发送失败,服务端可能会出现大量异常结果。In the communication method between the client and the server, when a response message sent by the client is received within a preset timeout period, the server is controlled to enter an idle state. In step S206, if the response message sent by the client is not received within the preset timeout period, data retransmission is required, and an error cannot be reported if no response message is received within a preset timeout period. The reason is that the response message is sent back after the client performs persistence processing, and the processing speed of the client and the network speed may be unstable. Therefore, the time for the response message from the client to reach the server fluctuates to a certain extent. If there is no response message, it is determined that the data packet has failed to be sent, and a large number of abnormal results may appear on the server.

正常情况下,如图4a所示的客户端和服务端间的消息传输的示意图中,服务器将数据以及同步序列标识syn号发送给客户端后,客户端先将数据缓存到本地,再将与syn对应的响应消息ack返回给服务端,服务端在预设超时时间段内接收到客户端发送的响应消息时,进入空闲状态;若在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作,在超时重传结束后,且没有更新的数据需要发送给客户端时,服务端进入空闲状态。Under normal circumstances, in the schematic diagram of message transmission between the client and the server as shown in Figure 4a, after the server sends the data and the syn number of the synchronization sequence identifier to the client, the client first caches the data locally, and then stores the data with The response message ack corresponding to syn is returned to the server. When the server receives the response message sent by the client within the preset timeout period, it enters the idle state; if it does not receive the response sent by the client within the preset timeout period When the message is sent, the data timeout retransmission operation is performed. After the timeout retransmission ends and there is no updated data to be sent to the client, the server enters the idle state.

在另一种可选地实施例中,如图4b所示的数据超时重传的示意图中,针对客户端回传的响应消息在网络中丢失的情况,此时服务端没有接收到客户端回传的响应消息,则进行数据超时重传的操作,客户端在第一次回传了响应消息后仍收到服务端发送的最大重传次数的数据包,则客户端需要在最后一次接收到数据包时再次回传该数据包的响应消息,以通知服务端。而服务端在发送最大重传次数的数据包之后,仍要等待预设超时时间段后才将异常记录到异常数据库中,等待预设超时时间段是为了等待客户端回传的最后一次响应消息。若服务端在该预设超时时间段内仍未收到客户端发送的响应消息,则将异常记录到异常数据库中;若服务端在该预设超时时间段内接收到客户端发送的响应消息,则无需记录异常。In another optional embodiment, in the schematic diagram of data timeout retransmission shown in Figure 4b, the response message returned by the client is lost in the network, and the server does not receive the If the response message is transmitted, the operation of retransmitting the data overtime will be performed. After the client returns the response message for the first time, it still receives the data packet with the maximum number of retransmissions sent by the server. When the data packet is received, the response message of the data packet is sent back again to notify the server. After the server sends the data packet with the maximum number of retransmissions, it still has to wait for the preset timeout period before recording the exception in the exception database. The reason for waiting for the preset timeout period is to wait for the last response message returned by the client. . If the server has not received the response message sent by the client within the preset timeout period, the exception will be recorded in the exception database; if the server receives the response message sent by the client within the preset timeout period , there is no need to log the exception.

在上述过程中,还存在一种概率很小但可能存在的情况,即在超时重传的过程中,服务端又更新了新的数据,此时服务端存在两种发送情况:当为低频操作时,则将最新更新的数据和超时重传的数据全部发送给客户端,重复传输对于网络的阻塞影响不明显,却能保证推送的数据都到达了客户端,客户端可以在幂等性基础上实现有条件的更新;当为高频操作时,则只传输最新更新的数据给客户端。In the above process, there is a small probability but possible situation, that is, in the process of overtime retransmission, the server updates new data. At this time, the server has two sending situations: when it is a low-frequency operation , the latest updated data and timeout retransmitted data are all sent to the client. The impact of repeated transmission on network congestion is not obvious, but it can ensure that all the pushed data reaches the client. The client can rely on idempotence Realize conditional update; when it is a high-frequency operation, only the latest updated data is transmitted to the client.

通过以上说明可以保证数据传输的可靠性,但还需对客户端的不稳定状态做数据一致性的方案设计。设计思路有两种,一种是保证客户端不发生异常,另一种是即使客户端发生异常,在恢复正常后依旧能保持数据的一致性。Through the above description, the reliability of data transmission can be guaranteed, but it is necessary to design a data consistency scheme for the unstable state of the client. There are two design ideas, one is to ensure that the client does not experience abnormalities, and the other is to maintain data consistency after the client returns to normal even if the client is abnormal.

可能导致客户端异常的原因有很多,诸如断电或者人为强制关机等因素,在这种情况下,无法通过任何技术手段避免,因此需要考虑如何在客户端恢复正常之后保持数据一致性的问题。There are many reasons that may cause the client to be abnormal, such as power failure or artificial forced shutdown. In this case, it cannot be avoided by any technical means. Therefore, it is necessary to consider how to maintain data consistency after the client returns to normal.

通过以下两种方案可以保证数据一致性,在图5所示的第一种客户端获取更新的数据包的流程图中,当客户端重启且网络恢复正常之后,客户端通过服务端查询之前所有的轮询接口,如数据包对应的接口或扫码激活的接口等,查询服务端是否有更新的数据,若服务端有更新的数据,则服务端向客户端发送存在更新的数据的第一消息,客户端接收到服务端发送的第一消息后,向服务端发送websocket连接请求,并建立客户端与服务端间的websocket通道,服务端将websocket通道建立成功的消息发送给客户端,并将更新的数据对应在数据库中的存储地址,即第二消息发送给客户端,其中,存储地址中携带有同步序列标识(syn号),客户端在接收到服务端发送的与更新的数据对应的存储地址的第二消息后,将第二消息中的存储地址缓存到本地,并将第二消息的响应消息(ack)回传给服务端,服务端在预设超时时间段内接收到客户端发送的响应消息时,进入空闲状态,客户端依据本地缓存的与更新的数据对应的存储地址,请求数据库中与第二消息对应的数据,数据库在接收客户端的请求消息后,将对应的数据返回给客户端。如果客户端向服务端发送websocket连接请求后,无法连接到服务端,则会在客户端告警提示用户无法连接服务端。Data consistency can be guaranteed through the following two schemes. In the flow chart of the first type of client obtaining updated data packets shown in Figure 5, when the client restarts and the network returns to normal, the client queries all previous data packets through the server. The polling interface, such as the interface corresponding to the data packet or the interface activated by scanning the code, etc., checks whether the server has updated data. If the server has updated data, the server will send the first message of the updated data to the client. message, the client sends a websocket connection request to the server after receiving the first message sent by the server, and establishes a websocket channel between the client and the server, and the server sends a message that the websocket channel is successfully established to the client, and The updated data corresponds to the storage address in the database, that is, the second message is sent to the client, wherein the storage address carries a synchronization sequence identifier (syn number), and the client receives the data corresponding to the updated data sent by the server. After the second message of the storage address of the second message, the storage address in the second message is cached locally, and the response message (ack) of the second message is sent back to the server, and the server receives the client within the preset timeout period When the response message sent by the terminal enters the idle state, the client requests the data corresponding to the second message in the database according to the storage address corresponding to the updated data in the local cache. After receiving the request message from the client, the database sends the corresponding data to returned to the client. If the client fails to connect to the server after sending a websocket connection request to the server, an alarm will be displayed on the client to prompt the user that the server cannot be connected.

图6是根据本申请实施例的第二种客户端获取更新的数据包的流程图,也可以保证数据的一致性,在图6中,当客户端重连且网络恢复正常之后,由客户端向服务端发送websocket连接请求,并建立客户端与服务端间的websocket通道,服务端将websocket通道建立成功的消息发送给客户端,并查询异常数据库中是否有未成功发送的数据,同时查询是否存在更新的数据,当存在更新的数据时,服务端将更新的数据对应在数据库中的存储地址以及之前未成功发送的数据对应的存储地址作为第三消息一并发送给客户端,其中,存储地址中携带有同步序列标识(syn号),客户端在接收到服务端发送的包含与更新的数据对应的存储地址以及之前未成功发送的数据对应的存储地址的第三消息后,将第三消息中的存储地址缓存到本地,并将第三消息的响应消息(ack)回传给服务端,服务端在预设超时时间段内接收到客户端发送的响应消息时,进入空闲状态,客户端依据本地缓存的第三消息中的存储地址,请求数据库中对应的数据,数据库在接收客户端的请求消息后,将对应的数据返回给客户端。如果客户端向服务端发送websocket连接请求后,无法连接到服务端,则会在客户端告警提示用户无法连接服务端。Fig. 6 is a flow chart of the second type of client obtaining updated data packets according to the embodiment of the present application, which can also ensure data consistency. In Fig. 6, when the client reconnects and the network returns to normal, the client Send a websocket connection request to the server, and establish a websocket channel between the client and the server. The server sends the message that the websocket channel is successfully established to the client, and checks whether there is any data that has not been successfully sent in the exception database. There is updated data, and when there is updated data, the server sends the storage address corresponding to the updated data in the database and the storage address corresponding to the previously unsuccessfully sent data to the client as a third message, wherein the storage The address carries a synchronization sequence identifier (syn number). After receiving the third message sent by the server that contains the storage address corresponding to the updated data and the storage address corresponding to the data that was not successfully sent before, the client sends the third The storage address in the message is cached locally, and the response message (ack) of the third message is sent back to the server. When the server receives the response message sent by the client within the preset timeout period, it enters the idle state, and the client The terminal requests the corresponding data in the database according to the storage address in the locally cached third message, and the database returns the corresponding data to the client after receiving the request message from the client. If the client fails to connect to the server after sending a websocket connection request to the server, an alarm will be displayed on the client to prompt the user that the server cannot be connected.

对比以上两种客户端获取更新的数据包的过程,可以得知,第二种方案优于第一种方案,原因在于推送数据这一过程全部集中在服务端,不需要再开通更多的接口给客户端进行调用,从而使得代码更具有高内聚性;其次,在第二种方案中,与上述由于网络抖动而进行的数据重传保持了一致。因此,在第二种方案中,无论客户端出于什么原因导致ws通道断开,一旦客户端的网络恢复正常时候,一律由服务端重传所有不成功的数据包,降低了其他开发人员的理解难度。Comparing the process of obtaining updated data packets by the above two clients, we can know that the second solution is better than the first one, because the process of pushing data is all concentrated on the server side, and no more interfaces need to be opened. Calling the client makes the code more cohesive; secondly, in the second solution, it is consistent with the above-mentioned data retransmission due to network jitter. Therefore, in the second solution, no matter what the client causes the ws channel to be disconnected, once the client’s network returns to normal, the server will retransmit all unsuccessful data packets, which reduces the understanding of other developers difficulty.

通过上述步骤,获取数据库中当前更新周期内更新的数据以及数据对应的存储地址,将存储地址发送给客户端,其中,存储地址中携带有同步序列标识,在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作,在数据重传次数达到预设阈值,且在预设超时时间段内未接收到客户端发送的响应消息的情况下,将存储地址所存储的数据记录到异常数据库中,并提示客户端发生异常,达到了依据数据超时重传保证数据的可靠性传输的目的,实现了将更新的数据及时通知客户端以确保数据一致性的技术效果,进而解决了服务端和客户端之间建立长连接时无法保证消息的可靠性和一致性的技术问题。Through the above steps, the data updated in the current update cycle in the database and the storage address corresponding to the data are obtained, and the storage address is sent to the client, wherein the storage address carries a synchronization sequence identifier, which is not received within the preset timeout period When the response message sent by the client, the operation of retransmitting the data overtime is performed. When the number of data retransmissions reaches the preset threshold and the response message sent by the client is not received within the preset timeout period, the address will be stored. The stored data is recorded in the exception database, and the client is notified of an exception, which achieves the purpose of ensuring the reliability of data transmission based on data overtime retransmission, and realizes the technology of notifying the client of updated data in time to ensure data consistency. Effect, and then solve the technical problem that the reliability and consistency of messages cannot be guaranteed when a long connection is established between the server and the client.

图7是根据本申请实施例的另一种客户端和服务端间的通信方法的流程图,即从客户端的角度对客户端和服务端间的通信方法进行说明,如图7所示,该方法包括如下步骤:Fig. 7 is a flowchart of another communication method between the client and the server according to an embodiment of the present application, that is, the communication method between the client and the server is described from the perspective of the client, as shown in Fig. 7 , the The method includes the following steps:

步骤S702,确定客户端的网络状态;Step S702, determining the network status of the client;

步骤S704,在客户端的网络状态为正常时,向服务端发送websocket连接请求;Step S704, when the network status of the client is normal, send a websocket connection request to the server;

步骤S706,接收服务端发送的成功建立连接的消息,以及接收服务端发送的与当前更新周期内更新的数据对应的存储地址,其中,存储地址中携带有同步序列标识,同步序列标识用于表示服务端发送的请求消息,更新的数据存储在数据库中;Step S706, receiving the message of successfully establishing the connection sent by the server, and receiving the storage address corresponding to the updated data in the current update cycle sent by the server, wherein the storage address carries a synchronization sequence identifier, which is used to indicate The request message sent by the server, the updated data is stored in the database;

步骤S708,将与存储地址和同步序列标识对应的响应消息发送给服务端。Step S708, sending a response message corresponding to the storage address and the synchronization sequence identifier to the server.

在该客户端和服务端间的通信方法中的步骤S706,接收服务端发送的与当前更新周期内更新的数据对应的存储地址之后,具体还包括如下步骤:将存储地址缓存到本地。In step S706 of the communication method between the client and the server, after receiving the storage address sent by the server and corresponding to the data updated in the current update cycle, the method further includes the following steps: caching the storage address locally.

在该客户端和服务端间的通信方法中的步骤S702至步骤S708中,根据客户端接收到的服务端发送的存储地址是否相同,方法还包括如下两个方面:在接收到服务端多次发送的相同存储地址的请求消息时,将最后一次接收到的请求消息中的存储地址缓存到本地,并将最后一次接收到的请求消息的响应消息发送给服务端;在接收到服务端多次发送的不同存储地址的请求消息时,将最后一次接收到的请求消息中的存储地址缓存到本地,并将最后一次接收到的请求消息的响应消息发送给服务端。需要说明的是,在最后一次接收到的请求消息中,可能包含未成功发送的数据以及更新的数据对应的存储地址,也可能仅包含未成功发送的数据的存储地址,或者仅包含更新的数据对应的地址,请求消息中具体包含的内容需要依据实际情况确定。In step S702 to step S708 in the communication method between the client and the server, according to whether the storage address sent by the server received by the client is the same, the method also includes the following two aspects: When sending a request message with the same storage address, the storage address in the last received request message is cached locally, and the response message of the last received request message is sent to the server; after receiving the server multiple times When sending request messages with different storage addresses, the storage address in the last received request message is cached locally, and the response message of the last received request message is sent to the server. It should be noted that in the last received request message, it may contain the storage address corresponding to the data that was not sent successfully and the updated data, or it may only contain the storage address of the data that was not sent successfully, or it may only contain the updated data The corresponding address and the specific content contained in the request message need to be determined according to the actual situation.

在该客户端和服务端间的通信方法中的步骤S708,将与存储地址和同步序列标识对应的响应消息发送给服务端之后,如图8所示的流程图,方法具体还包括如下步骤:In step S708 in the communication method between the client and the server, after sending the response message corresponding to the storage address and the synchronization sequence identifier to the server, as shown in the flow chart in Figure 8, the method specifically includes the following steps:

步骤S802,依据存储地址请求数据库中与存储地址对应的数据;Step S802, requesting data corresponding to the storage address in the database according to the storage address;

步骤S804,接收数据库返回的与存储地址对应的数据。Step S804, receiving the data corresponding to the storage address returned by the database.

图9是根据本申请实施例的又一种客户端和服务端间的通信方法的流程图,即从数据库的角度对客户端和服务端间的通信方法进行说明,如图9所示,方法包括如下步骤:Fig. 9 is a flowchart of another communication method between the client and the server according to the embodiment of the present application, that is, the communication method between the client and the server is described from the perspective of the database, as shown in Fig. 9, the method Including the following steps:

步骤S902,获取服务端更新的数据;Step S902, acquiring data updated by the server;

步骤S904,存储更新的数据,并将更新的数据对应的存储地址返回给服务端;Step S904, storing the updated data, and returning the storage address corresponding to the updated data to the server;

步骤S906,接收客户端的数据请求,其中,数据请求中包括与更新的数据对应的存储地址;Step S906, receiving a data request from the client, wherein the data request includes a storage address corresponding to the updated data;

步骤S908,将与存储地址对应的数据返回给客户端。Step S908, returning the data corresponding to the storage address to the client.

图10是根据本申请实施例的一种客户端和服务端间的通信装置的结构图,如图10所示,该装置包括:FIG. 10 is a structural diagram of a communication device between a client and a server according to an embodiment of the present application. As shown in FIG. 10 , the device includes:

获取模块1002,用于获取数据库中当前更新周期内更新的数据以及数据对应的存储地址;An acquisition module 1002, configured to acquire data updated in the current update period in the database and a storage address corresponding to the data;

发送模块1004,用于将存储地址发送给客户端,其中,存储地址中携带有同步序列标识,同步序列标识用于表示服务端发送的请求消息;The sending module 1004 is configured to send the storage address to the client, wherein the storage address carries a synchronization sequence identifier, and the synchronization sequence identifier is used to represent a request message sent by the server;

处理模块1006,用于在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作,其中,响应消息为对与存储地址和同步序列标识所对应的数据重传结果的响应;The processing module 1006 is configured to perform data overtime retransmission when the response message sent by the client is not received within the preset timeout period, wherein the response message is to retransmit the data corresponding to the storage address and the synchronization sequence identifier Response to the result;

提示模块1008,用于在数据重传次数达到预设阈值,且在预设超时时间段内未接收到客户端发送的响应消息的情况下,将存储地址所存储的数据记录到异常数据库中,并提示客户端发生异常。Prompt module 1008, configured to record the data stored in the storage address into the exception database when the number of times of data retransmission reaches a preset threshold and no response message sent by the client is received within the preset timeout period, And prompt the client to have an exception.

需要说明的是,图10所示的客户端和服务端间的通信装置用于执行图2至图9所示的客户端和服务端间的通信方法,因此上述客户端和服务端间的通信方法中的相关解释说明也适用于该客户端和服务端间的通信装置,此处不再赘述。It should be noted that the communication device between the client and the server shown in FIG. 10 is used to execute the communication methods between the client and the server shown in FIGS. 2 to 9 , so the above-mentioned communication between the client and the server Relevant explanations in the method are also applicable to the communication device between the client and the server, and will not be repeated here.

本申请实施例还提供了一种非易失性存储介质,该非易失性存储介质包括存储的程序,其中,在程序运行时控制该非易失性存储介质所在设备执行以下的客户端和服务端间的通信方法:获取数据库中当前更新周期内更新的数据以及数据对应的存储地址;将存储地址发送给客户端,其中,存储地址中携带有同步序列标识,同步序列标识用于表示服务端发送的请求消息;在预设超时时间段内未接收到客户端发送的响应消息时,进行数据超时重传的操作,其中,响应消息为对与存储地址和同步序列标识所对应的数据重传结果的响应;在数据重传次数达到预设阈值,且在预设超时时间段内未接收到客户端发送的响应消息的情况下,将存储地址所存储的数据记录到异常数据库中,并提示客户端发生异常。The embodiment of the present application also provides a non-volatile storage medium, the non-volatile storage medium includes a stored program, wherein, when the program is running, the device where the non-volatile storage medium is located is controlled to execute the following client and Communication method between servers: Obtain the data updated in the current update cycle in the database and the storage address corresponding to the data; send the storage address to the client, where the storage address carries a synchronization sequence identifier, which is used to indicate the service The request message sent by the terminal; when the response message sent by the client is not received within the preset timeout period, the operation of data overtime retransmission is performed, wherein the response message is the retransmission of the data corresponding to the storage address and the synchronization sequence identifier Response to the transmission result; when the number of data retransmissions reaches the preset threshold and the response message sent by the client is not received within the preset timeout period, the data stored in the storage address is recorded in the exception database, and Prompt the client that an exception has occurred.

上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The serial numbers of the above embodiments of the present application are for description only, and do not represent the advantages and disadvantages of the embodiments.

在本申请的上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。In the above-mentioned embodiments of the present application, the descriptions of each embodiment have their own emphases, and for parts not described in detail in a certain embodiment, reference may be made to relevant descriptions of other embodiments.

在本申请所提供的几个实施例中,应该理解到,所揭露的技术内容,可通过其它的方式实现。其中,以上所描述的装置实施例仅仅是示意性的,例如所述单元的划分,可以为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,单元或模块的间接耦合或通信连接,可以是电性或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed technical content can be realized in other ways. Wherein, the device embodiments described above are only illustrative. For example, the division of the units may be a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or may be Integrate into another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of units or modules may be in electrical or other forms.

所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.

所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可为个人计算机、服务器或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or part of the contribution to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , including several instructions for enabling a computer device (which may be a personal computer, server or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes. .

以上所述仅是本申请的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本申请的保护范围。The above description is only the preferred embodiment of the present application. It should be pointed out that for those of ordinary skill in the art, without departing from the principle of the present application, some improvements and modifications can also be made. These improvements and modifications are also It should be regarded as the protection scope of this application.

Claims (13)

1. A method of communication between a client and a server, comprising:
acquiring updated data in a current updating period in a database and a storage address corresponding to the data;
the storage address is sent to a client, wherein the storage address carries a synchronization sequence identifier, and the synchronization sequence identifier is used for representing a request message sent by a server;
when a response message sent by the client is not received within a preset timeout period, performing data timeout retransmission, wherein the response message is a response to a data retransmission result corresponding to the storage address and the synchronous sequence identifier;
and under the condition that the data retransmission times reach a preset threshold value and the response message sent by the client is not received within the preset timeout period, recording the data stored by the storage address into an abnormal database, and prompting the client to be abnormal.
2. The method of communication between a client and a server of claim 1, wherein prior to sending the storage address to the client, the method further comprises:
receiving a secure socket connection request sent by the client;
And sending the message of successfully establishing the connection between the client and the server to the client.
3. The communication method between the client and the server according to claim 2, wherein the websocket connection request carries identification information of the client; the method further comprises the steps of: and after the client and the server are successfully connected, the identification information of the client is stored in the server.
4. The method of communication between a client and a server according to claim 1, wherein the synchronization sequence identification includes: and the character string is obtained after the identification information of the client and the time stamp are encoded.
5. The method according to claim 1, wherein the response message is consistent with the synchronization sequence identifier, and the preset timeout period is determined according to a time of the client buffering the storage address corresponding to the data, a round trip time of the storage address and the synchronization sequence identifier between the client and the server, and a redundancy time.
6. The communication method between a client and a server according to any one of claims 1 to 5, characterized in that the method further comprises: and when receiving the response message sent by the client in the preset timeout period, controlling the server to enter an idle state.
7. A method of communication between a client and a server, comprising:
determining the network state of the client;
when the network state of the client is normal, sending a secure socket connection request to a server;
receiving a message that the client and the server successfully establish connection and a storage address corresponding to data updated in a current update period, wherein the storage address carries a synchronization sequence identifier, the synchronization sequence identifier is used for indicating a request message sent by the server, and the updated data is stored in a database;
and sending a response message corresponding to the storage address and the synchronous sequence identifier to the server.
8. The method according to claim 7, wherein after receiving a storage address corresponding to data updated in a current update period sent by the server, the method further comprises: and caching the storage address to the local.
9. The method of communication between a client and a server of claim 7, further comprising:
When receiving the request messages with the same storage address sent by the server for many times, caching the storage address in the request message received last time to the local and sending the response message of the request message received last time to the server;
when receiving the request messages of different storage addresses sent by the server for many times, caching the storage address in the request message received last time to the local and sending the response message of the request message received last time to the server.
10. The method according to claim 7, wherein after transmitting a response message corresponding to the storage address and the synchronization sequence identification to the server, the method further comprises:
requesting data corresponding to the storage address in the database according to the storage address;
and receiving data corresponding to the storage address returned by the database.
11. A communication device between a client and a server, comprising:
the acquisition module is used for acquiring the data updated in the current update period in the database and the storage address corresponding to the data;
The sending module is used for sending the storage address to the client, wherein the storage address carries a synchronous sequence identifier, and the synchronous sequence identifier is used for representing a request message sent by the server;
a processing module, configured to perform an operation of data timeout retransmission when a response message sent by the client is not received within a preset timeout period, where the response message is a response to a data retransmission result corresponding to the storage address and the synchronization sequence identifier
The prompting module is used for recording the data stored by the storage address into an abnormal database and prompting the client to be abnormal when the data retransmission times reach a preset threshold value and the response message sent by the client is not received within the preset timeout period.
12. An electronic device, comprising:
a memory for storing program instructions;
a processor, coupled to the memory, for executing program instructions that perform the following functions: acquiring updated data in a current updating period in a database and a storage address corresponding to the data; the storage address is sent to a client, wherein the storage address carries a synchronization sequence identifier, and the synchronization sequence identifier is used for representing a request message sent by a server; when a response message sent by the client is not received within a preset timeout period, performing data timeout retransmission, wherein the response message is a response to a data retransmission result corresponding to the storage address and the synchronous sequence identifier; and under the condition that the data retransmission times reach a preset threshold value and the response message sent by the client is not received within the preset timeout period, recording the data stored by the storage address into an abnormal database, and prompting the client to be abnormal.
13. A non-volatile storage medium, characterized in that the non-volatile storage medium comprises a stored program, wherein the program, when run, controls a device in which the non-volatile storage medium is located to perform the communication method between the client and the service according to any one of claims 1 to 6.
CN202210123000.5A 2022-02-09 2022-02-09 Communication method, device and electronic equipment between client and server Pending CN116614485A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210123000.5A CN116614485A (en) 2022-02-09 2022-02-09 Communication method, device and electronic equipment between client and server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210123000.5A CN116614485A (en) 2022-02-09 2022-02-09 Communication method, device and electronic equipment between client and server

Publications (1)

Publication Number Publication Date
CN116614485A true CN116614485A (en) 2023-08-18

Family

ID=87675176

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210123000.5A Pending CN116614485A (en) 2022-02-09 2022-02-09 Communication method, device and electronic equipment between client and server

Country Status (1)

Country Link
CN (1) CN116614485A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117692364A (en) * 2023-11-23 2024-03-12 小米汽车科技有限公司 Vehicle-mounted Ethernet self-checking method and device and electronic equipment
CN119363738A (en) * 2024-11-11 2025-01-24 国网福建省电力有限公司龙岩供电公司 Performance optimization method, system and storage medium for transmission network
CN119993127A (en) * 2025-03-24 2025-05-13 珠海格力电器股份有限公司 Updating method, device, local host, server, system and storage medium
CN120075172A (en) * 2025-04-25 2025-05-30 苏州元脑智能科技有限公司 Timeout setting method, interactive device, medium, and program product

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106506601A (en) * 2016-10-12 2017-03-15 北京奇虎科技有限公司 Method and device for data transmission
CN106713328A (en) * 2016-12-29 2017-05-24 北京奇虎科技有限公司 Information processing method and apparatus based on long connection
CN107315825A (en) * 2017-07-05 2017-11-03 北京奇艺世纪科技有限公司 A kind of index upgrade system, method and device
CN110753129A (en) * 2019-10-29 2020-02-04 深圳前海微众银行股份有限公司 Message transmission method, system, apparatus, device, and computer-readable storage medium
CN112637151A (en) * 2020-12-11 2021-04-09 深圳市英威腾电气股份有限公司 Data message transmission method, terminal device, server and storage medium
CN113055499A (en) * 2021-05-31 2021-06-29 云和恩墨(北京)信息技术有限公司 Data transmission method and system

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106506601A (en) * 2016-10-12 2017-03-15 北京奇虎科技有限公司 Method and device for data transmission
CN106713328A (en) * 2016-12-29 2017-05-24 北京奇虎科技有限公司 Information processing method and apparatus based on long connection
CN107315825A (en) * 2017-07-05 2017-11-03 北京奇艺世纪科技有限公司 A kind of index upgrade system, method and device
CN110753129A (en) * 2019-10-29 2020-02-04 深圳前海微众银行股份有限公司 Message transmission method, system, apparatus, device, and computer-readable storage medium
CN112637151A (en) * 2020-12-11 2021-04-09 深圳市英威腾电气股份有限公司 Data message transmission method, terminal device, server and storage medium
CN113055499A (en) * 2021-05-31 2021-06-29 云和恩墨(北京)信息技术有限公司 Data transmission method and system

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117692364A (en) * 2023-11-23 2024-03-12 小米汽车科技有限公司 Vehicle-mounted Ethernet self-checking method and device and electronic equipment
CN119363738A (en) * 2024-11-11 2025-01-24 国网福建省电力有限公司龙岩供电公司 Performance optimization method, system and storage medium for transmission network
CN119993127A (en) * 2025-03-24 2025-05-13 珠海格力电器股份有限公司 Updating method, device, local host, server, system and storage medium
CN120075172A (en) * 2025-04-25 2025-05-30 苏州元脑智能科技有限公司 Timeout setting method, interactive device, medium, and program product

Similar Documents

Publication Publication Date Title
CN116614485A (en) Communication method, device and electronic equipment between client and server
CN110620890B (en) File uploading method and system
CN109561159B (en) Data processing method and system based on Websocket long connection
US7532577B2 (en) Managing transmission control protocol (TCP) connections
CN113630465B (en) Message processing method, device, equipment and storage medium
CN111371631B (en) Heartbeat mechanism detection method, terminal device and storage medium
TWI740210B (en) Method for terminal device management and server
CN103973414A (en) Data transmission method and device
CN116599953B (en) File uploading method, device, system, equipment and readable storage medium
CN111613161A (en) Display data transmission method, display device and storage medium
CN105681160A (en) Methods and apparatuses for correcting session message disorder in instant communication system
CN105978796A (en) Message communication method and system based on unstable mobile network
US8422370B2 (en) Reducing retransmission of out of order packets
US8762449B2 (en) Method of downloading large size data to a large number of networked client machines from a single server
CN111431964A (en) A message synchronization processing method, device and storage medium
CN107707689A (en) A kind of DHCP message processing method, Dynamic Host Configuration Protocol server and gateway device
CN114500243B (en) Data communication method, device, computer readable medium and electronic equipment
JP2010213150A (en) Transmitter, file distribution system, file distribution control method and file distribution control program in system
EP4496289A2 (en) Sequence number synchronization method and apparatus
CN106230747B (en) Method, device and system for recovering TCP connection sequence number
CN107786607B (en) Message retransmission method, message retransmission server and user equipment
CN106790728A (en) information push method and system
US11444882B2 (en) Methods for dynamically controlling transmission control protocol push functionality and devices thereof
CN102904764A (en) A data transmission device and transmission method thereof
US10949645B2 (en) Method, apparatus, and storage medium for data verification

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination