[go: up one dir, main page]

CN103532984B - Data transmission method, device and system of websocket protocol - Google Patents

Data transmission method, device and system of websocket protocol Download PDF

Info

Publication number
CN103532984B
CN103532984B CN201310535026.1A CN201310535026A CN103532984B CN 103532984 B CN103532984 B CN 103532984B CN 201310535026 A CN201310535026 A CN 201310535026A CN 103532984 B CN103532984 B CN 103532984B
Authority
CN
China
Prior art keywords
compression
client
compression type
type
server
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.)
Active
Application number
CN201310535026.1A
Other languages
Chinese (zh)
Other versions
CN103532984A (en
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.)
China United Network Communications Group Co Ltd
Original Assignee
China United Network Communications Group 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 China United Network Communications Group Co Ltd filed Critical China United Network Communications Group Co Ltd
Priority to CN201310535026.1A priority Critical patent/CN103532984B/en
Publication of CN103532984A publication Critical patent/CN103532984A/en
Application granted granted Critical
Publication of CN103532984B publication Critical patent/CN103532984B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Transfer Between Computers (AREA)
  • Computer And Data Communications (AREA)

Abstract

本发明提供一种websocket协议的数据传输方法、设备和系统,其中,该方法包括:首先支持websocket的服务器通过与支持websocket的客户端协商所共同支持的压缩类型信息,然后确定与待传输的原始文件的类型匹配的第一压缩类型,应用与第一压缩类型对应的压缩算法对原始文件进行压缩处理,并通过TCPsocket通道将应用第一压缩类型标识的压缩文件发送给客户端,客户端应用与第一压缩类型对应的压缩算法对压缩文件进行解压缩处理获取原始文件,从而提高了客户端与服务器指间基于websocket协议的数据传输效率。

The present invention provides a data transmission method, device and system of the websocket protocol, wherein the method includes: firstly, the server supporting websocket negotiates with the client supporting the websocket to jointly support the compression type information, and then determines the original compression type information to be transmitted The first compression type matching the type of the file, apply the compression algorithm corresponding to the first compression type to compress the original file, and send the compressed file with the identification of the first compression type to the client through the TCP socket channel, the client application and The compression algorithm corresponding to the first compression type decompresses the compressed file to obtain the original file, thereby improving the data transmission efficiency between the client and the server based on the websocket protocol.

Description

websocket协议的数据传输方法、设备和系统Data transmission method, device and system of websocket protocol

技术领域technical field

本发明实施例涉及通信技术领域,尤其涉及一种websocket协议的数据传输方法、设备和系统。The embodiment of the present invention relates to the field of communication technology, and in particular to a data transmission method, device and system of the websocket protocol.

背景技术Background technique

很多网站为了实现即时通讯采用轮询技术,即在特定的时间间隔,由客户端对服务器发出HTTP请求,然后由服务器返回最新的数据给客户端。这种传统模式带来很明显的缺点是客户端需要不断的向服务器发出请求,然而HTTP请求的报文头是非常长的,里面包含的数据可能只是一个很小的值,这样会占用很多的带宽。Many websites use polling technology to implement instant messaging, that is, at a specific time interval, the client sends an HTTP request to the server, and then the server returns the latest data to the client. The obvious disadvantage of this traditional mode is that the client needs to continuously send requests to the server. However, the header of the HTTP request is very long, and the data contained in it may only be a small value, which will take up a lot of time. bandwidth.

为了解决上述问题,实现了客户端与服务器全双工通信(full-duplex),HTML5中采用WebSocket协议,基于WebSocket协议,客户端和服务器只需要要做一个握手的动作,然后,客户端和服务器之间就形成了一条快速通道,两者之间就直接可以实现数据互相实时传送。但是,现有技术中,客户端与服务器之间的websocket的报文采用直接传输方式,因此,在实际应用中随着通信交互内容的海量增加,影响了数据传输的效率。In order to solve the above problems, full-duplex communication (full-duplex) between the client and the server is realized. The WebSocket protocol is adopted in HTML5. Based on the WebSocket protocol, the client and the server only need to do a handshake action, and then, the client and the server A fast channel is formed between them, and the two can directly transmit data to each other in real time. However, in the prior art, the websocket messages between the client and the server are directly transmitted. Therefore, in practical applications, the efficiency of data transmission is affected with the massive increase of communication interaction content.

发明内容Contents of the invention

针对现有技术的上述缺陷,本发明实施例提供一种websocket协议的数据传输方法、设备和系统。In view of the above-mentioned defects in the prior art, the embodiments of the present invention provide a data transmission method, device and system of the websocket protocol.

本发明一方面提供一种websocket协议的数据传输方法,包括:One aspect of the present invention provides a data transmission method of the websocket protocol, including:

支持websocket的服务器与支持websocket的客户端协商所共同支持的压缩类型信息,根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的第一压缩类型;The server that supports websocket negotiates with the client that supports websocket about the commonly supported compression type information, and determines the first compression type that matches the type of the original file to be transmitted to the client according to the compression type information;

所述服务器应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理,并通过与所述客户端之间的TCPsocket通道将应用所述第一压缩类型标识的压缩文件发送给所述客户端,以供所述客户端应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。The server applies a compression algorithm corresponding to the first compression type to compress the original file, and sends the compressed file identified by the first compression type to the The client is used for the client to apply a compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file.

本发明另一方面提供一种websocket协议的数据传输方法,包括:Another aspect of the present invention provides a data transmission method of the websocket protocol, including:

支持websocket的客户端与支持websocket的服务器协商所共同支持的压缩类型信息;The client that supports websocket negotiates with the server that supports websocket to support the compression type information;

所述客户端通过与所述服务器之间的TCPsocket通道接收应用第一压缩类型标识的压缩文件,其中,所述第一压缩类型是所述服务器根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的压缩类型;The client receives the compressed file marked with the first compression type through the TCP socket channel between the client and the server, wherein the first compression type is determined by the server according to the compression type information and is to be transmitted to the The client's original file type matches the compression type;

所述客户端应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。The client applies a compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file.

本发明又一方面提供一种支持websocket的服务器,包括:Another aspect of the present invention provides a server supporting websocket, including:

匹配模块,用于与支持websocket的客户端协商所共同支持的压缩类型信息,根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的第一压缩类型;A matching module, configured to negotiate with the websocket-supporting client on commonly supported compression type information, and determine a first compression type that matches the type of the original file to be transmitted to the client according to the compression type information;

处理模块,用于应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理,并通过与所述客户端之间的TCPsocket通道将应用所述第一压缩类型标识的压缩文件发送给所述客户端,以供所述客户端应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。A processing module, configured to apply a compression algorithm corresponding to the first compression type to compress the original file, and compress the compressed file identified by the first compression type through the TCP socket channel with the client and send it to the client, so that the client applies the compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file.

本发明再一方面提供一种支持websocket的客户端,包括:Another aspect of the present invention provides a client supporting websocket, including:

预处理模块,用于与支持websocket的服务器协商所共同支持的压缩类型信息;The preprocessing module is used for negotiating the commonly supported compression type information with the server supporting websocket;

接收模块,用于通过与所述服务器之间的TCPsocket通道接收应用第一压缩类型标识的压缩文件,其中,所述第一压缩类型是所述服务器根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的压缩类型;A receiving module, configured to receive a compressed file marked with a first compression type through a TCP socket channel with the server, wherein the first compression type is determined by the server according to the compression type information and is to be transmitted to the The type of compression that matches the type of the original file on the client side;

解压缩模块,用于应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。A decompression module, configured to apply a compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file.

本发明又一方面提供一种基于websocket协议的数据传输系统,包括:上述的支持websocket的服务器和支持websocket的客户端。Another aspect of the present invention provides a data transmission system based on the websocket protocol, including: the above-mentioned websocket-supporting server and websocket-supporting client.

本发明实施例提供的websocket协议的数据传输方法、设备和系统,首先支持websocket的服务器通过与支持websocket的客户端协商所共同支持的压缩类型信息,然后确定与待传输的原始文件的类型匹配的第一压缩类型,应用与第一压缩类型对应的压缩算法对原始文件进行压缩处理,并通过TCPsocket通道将应用第一压缩类型标识的压缩文件发送给客户端,客户端应用与第一压缩类型对应的压缩算法对压缩文件进行解压缩处理获取原始文件,从而提高了客户端与服务器指间基于websocket协议的数据传输效率。In the data transmission method, device and system of the websocket protocol provided by the embodiments of the present invention, first, the server supporting websocket negotiates with the client supporting the websocket to support the compression type information, and then determines the type of original file to be transmitted. The first compression type, apply the compression algorithm corresponding to the first compression type to compress the original file, and send the compressed file with the identification of the first compression type to the client through the TCP socket channel, and the client application corresponds to the first compression type The compression algorithm decompresses the compressed file to obtain the original file, thereby improving the data transmission efficiency between the client and the server based on the websocket protocol.

附图说明Description of drawings

图1为本发明实施例提供的一个websocket协议的数据传输方法的流程图;Fig. 1 is the flowchart of the data transmission method of a websocket agreement that the embodiment of the present invention provides;

图2为本发明实施例提供的另一个websocket协议的数据传输方法的流程图;Fig. 2 is the flowchart of the data transmission method of another websocket protocol that the embodiment of the present invention provides;

图3为本发明实施例提供的一个支持websocket的服务器的结构示意图;Fig. 3 is a schematic structural diagram of a websocket-supporting server provided by an embodiment of the present invention;

图4为本发明实施例提供的一个支持websocket的客户端的结构示意图;Fig. 4 is a schematic structural diagram of a client supporting websocket provided by an embodiment of the present invention;

图5为本发明实施例提供的一个基于websocket协议的数据传输系统的结构示意图。FIG. 5 is a schematic structural diagram of a data transmission system based on the websocket protocol provided by an embodiment of the present invention.

具体实施方式detailed description

图1为本发明实施例提供的一个websocket协议的数据传输方法的流程图,如图1所示,该方法包括:Fig. 1 is the flow chart of the data transmission method of a websocket agreement that the embodiment of the present invention provides, as shown in Fig. 1, this method comprises:

步骤100,支持websocket的服务器与支持websocket的客户端协商所共同支持的压缩类型信息,根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的第一压缩类型;Step 100, the server that supports websocket negotiates with the client that supports websocket about the compression type information that they support, and determines the first compression type that matches the type of the original file to be transmitted to the client according to the compression type information;

支持websocket的服务器在接收支持websocket的客户端发送的访问请求,以及根据访问请求向客户端返回用户所需要的原始文件之前,服务器首先与客户端协商所共同支持的压缩类型信息,协商过程具体包括:客户端向服务器发送自身所支持的压缩类型信息,比如gzip、rar、zip、cab、7z、tar等等,服务器根据自身所支持的压缩类型信息与客户端发送的压缩类型信息进行比较,选取相同的压缩类型作为双方所共同支持的压缩类型信息,并反馈给客户端。然后服务器从双方所共同支持的压缩类型信息中确定与待传输给客户端的原始文件的类型匹配的第一压缩类型,具体的确定过程为服务器本地存储有文件类型与压缩类型的对应关系,该对应关系是基于本领域技术人员应用与不同的压缩类型对应的压缩算法对不同类型的文件进行压缩效率测试所获取的,从而服务器查询该对应关系获取与待传输给客户端的原始文件的类型匹配的第一压缩类型。Before the websocket-supporting server receives the access request sent by the websocket-supporting client and returns the original file required by the user to the client according to the access request, the server first negotiates with the client about the compression type information it supports. The negotiation process specifically includes : The client sends the compression type information it supports to the server, such as gzip, rar, zip, cab, 7z, tar, etc., and the server compares the compression type information supported by itself with the compression type information sent by the client, and selects The same compression type is used as the compression type information supported by both parties, and is fed back to the client. Then the server determines the first compression type that matches the type of the original file to be transmitted to the client from the compression type information supported by both parties. The specific determination process is that the server locally stores the correspondence between the file type and the compression type. The relationship is based on those skilled in the art applying compression algorithms corresponding to different compression types to perform compression efficiency tests on different types of files, so that the server queries the corresponding relationship to obtain the first file that matches the type of the original file to be transmitted to the client. A compression type.

步骤101,所述服务器应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理,并通过与所述客户端之间的TCPsocket通道将应用所述第一压缩类型标识的压缩文件发送给所述客户端,以供所述客户端应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。Step 101, the server applies the compression algorithm corresponding to the first compression type to compress the original file, and applies the compression identified by the first compression type through the TCP socket channel with the client. The file is sent to the client, so that the client applies a compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file.

服务器确定与待传输给客户端的原始文件的类型匹配的第一压缩类型之后,应用与第一压缩类型对应的压缩算法对该原始文件进行压缩处理,需要说明的是,应用压缩算法对该原始文件进行压缩处理属于现有技术,此处不再赘述,仅仅以gzip压缩算法为例简单说明,比如应用gzip压缩算法压缩HTML文件的过程为:寻找输入数据内的重复字符串,二次出现的字符串由一个指向前一字符串的指针代替,其中,指针以对的形式--距离和长度来表示,假如距离限定为32KB,长度限定为258字节,若二次出现的字符串没有在这前32KB内出现,它就会作为文字字节序列发出。进一步地,为了提高压缩效率,服务器在对原始文件进行压缩处理之前,首先判断该原始文件的大小是否大于等于预设的阈值,若判断获知该原始文件的大小大于等于该阈值,则应用与第一压缩类型对应的压缩算法对原始文件进行压缩处理,若判断获知该原始文件的大小小于该阈值,则将该原始文件移入缓存区,达到预设的缓存时间后,再应用与第一压缩类型对应的压缩算法对存入缓存区的一个或多个原始文件进行压缩处理。服务器在对原始文件进行压缩处理完成后,将应用第一压缩类型标识的压缩文件通过与客户端之间的TCPsocket通道发送给客户端,客户端接收应用第一压缩类型标识的压缩文件后获知该压缩文件是服务器应用与第一压缩类型对应的压缩算法进行压缩的,因此客户端则应用与第一压缩类型对应的压缩算法对该压缩文件进行解压缩处理获取原始文件,并将原始文件通过客户端显示给用户。After the server determines the first compression type that matches the type of the original file to be transmitted to the client, it applies the compression algorithm corresponding to the first compression type to compress the original file. It should be noted that the original file is compressed using the compression algorithm Compression processing belongs to the prior art, so I won’t go into details here, and just take the gzip compression algorithm as an example for a brief description. For example, the process of applying the gzip compression algorithm to compress HTML files is: looking for repeated strings in the input data, characters that appear twice The string is replaced by a pointer to the previous string, where the pointer is expressed in the form of a pair - distance and length. If the distance is limited to 32KB, the length is limited to 258 bytes. If the string that appears twice is not here appears within the first 32KB, it is emitted as a sequence of literal bytes. Further, in order to improve the compression efficiency, before compressing the original file, the server first judges whether the size of the original file is greater than or equal to a preset threshold, and if it is judged that the size of the original file is greater than or equal to the threshold, then apply and A compression algorithm corresponding to a compression type compresses the original file. If it is judged that the size of the original file is smaller than the threshold, the original file is moved into the cache area. After the preset cache time is reached, the first compression type is applied. The corresponding compression algorithm performs compression processing on one or more original files stored in the cache area. After the server compresses the original file, it sends the compressed file marked with the first compression type to the client through the TCP socket channel with the client, and the client knows the compressed file after receiving the compressed file marked with the first compression type The compressed file is compressed by the server using the compression algorithm corresponding to the first compression type, so the client applies the compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file, and passes the original file through the client displayed to the user.

本实施例提供的websocket协议的数据传输方法,首先支持websocket的服务器通过与支持websocket的客户端协商所共同支持的压缩类型信息,然后确定与待传输的原始文件的类型匹配的第一压缩类型,应用与第一压缩类型对应的压缩算法对原始文件进行压缩处理,并通过TCPsocket通道将应用第一压缩类型标识的压缩文件发送给客户端,客户端应用与第一压缩类型对应的压缩算法对压缩文件进行解压缩处理获取原始文件,从而提高了客户端与服务器指间基于websocket协议的数据传输效率。In the data transmission method of the websocket protocol provided by this embodiment, first, the server supporting websocket negotiates with the client supporting the websocket to jointly support the compression type information, and then determines the first compression type that matches the type of the original file to be transmitted, Apply the compression algorithm corresponding to the first compression type to compress the original file, and send the compressed file marked with the first compression type to the client through the TCP socket channel, and the client applies the compression algorithm corresponding to the first compression type to compress the original file. The file is decompressed to obtain the original file, thereby improving the data transmission efficiency between the client and the server based on the websocket protocol.

基于上述实施例,进一步地,所述方法还包括:当客户端需要应用第二压缩类型进行解压缩时,可以主动向服务器发送包括第二压缩类型的变更请求,从而当服务器接收客户端发送的包括第二压缩类型的更新请求消息,若判断获知自身支持该第二压缩类型,则用当前的压缩算法处理完当前要传输的原始文件后,就应用与第二压缩类型对应的压缩算法对后续待传输给客户端的原始文件进行压缩处理,并将应用第二压缩类型标识的压缩文件通过与客户端之间的TCPsocket通道发送给客户端,客户端接收应用第二压缩类型标识的压缩文件后获知该压缩文件是服务器应用与第二压缩类型对应的压缩算法进行压缩的,因此客户端则应用与第二压缩类型对应的压缩算法对该压缩文件进行解压缩处理获取原始文件,并将原始文件通过客户端显示给用户。Based on the above embodiment, further, the method further includes: when the client needs to apply the second compression type for decompression, it can actively send a change request including the second compression type to the server, so that when the server receives the Including the update request message of the second compression type, if it is judged that it supports the second compression type, after the original file to be transmitted is processed by the current compression algorithm, the compression algorithm corresponding to the second compression type is applied to the subsequent The original file to be transmitted to the client is compressed, and the compressed file with the second compression type identification is sent to the client through the TCP socket channel between the client and the client. After receiving the compressed file with the second compression type identification, the client knows The compressed file is compressed by the server using the compression algorithm corresponding to the second compression type, so the client uses the compression algorithm corresponding to the second compression type to decompress the compressed file to obtain the original file, and pass the original file through displayed to the user by the client.

图2为本发明实施例提供的另一个websocket协议的数据传输方法的流程图,如图2所示,该方法包括:Fig. 2 is the flowchart of the data transmission method of another websocket protocol that the embodiment of the present invention provides, as shown in Fig. 2, this method comprises:

步骤200,支持websocket的客户端与支持websocket的服务器协商所共同支持的压缩类型信息;In step 200, the websocket-supporting client negotiates with the websocket-supporting server about the commonly supported compression type information;

步骤201,所述客户端通过与所述服务器之间的TCPsocket通道接收应用第一压缩类型标识的压缩文件,其中,所述第一压缩类型是所述服务器根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的压缩类型;Step 201, the client receives the compressed file identified by the first compression type through the TCP socket channel between the client and the server, wherein the first compression type is determined by the server according to the compression type information and is to be transmitted a compression type that matches the type of the client's original file;

步骤202,所述客户端应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。Step 202, the client applies a compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file.

本实施例提供的websocket协议的数据传输方法中各步骤的具体处理流程,可以参见上述图1所示的方法实施例,其实现原理和技术效果类似,此处不再赘述。For the specific processing flow of each step in the data transmission method of the websocket protocol provided in this embodiment, refer to the method embodiment shown in FIG. 1 above. The implementation principle and technical effect are similar and will not be repeated here.

本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。Those of ordinary skill in the art can understand that all or part of the steps for realizing the above-mentioned method embodiments can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the It includes the steps of the above method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other various media that can store program codes.

图3为本发明实施例提供的一个支持websocket的服务器的结构示意图,如图3所示,该服务器包括:匹配模块11和处理模块12,其中,匹配模块11用于与支持websocket的客户端协商所共同支持的压缩类型信息,根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的第一压缩类型;处理模块12用于应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理,并通过与所述客户端之间的TCPsocket通道将应用所述第一压缩类型标识的压缩文件发送给所述客户端,以供所述客户端应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。Fig. 3 is a schematic structural diagram of a websocket-supporting server provided by an embodiment of the present invention. As shown in Fig. 3, the server includes: a matching module 11 and a processing module 12, wherein the matching module 11 is used to negotiate with a websocket-supporting client Commonly supported compression type information, determining a first compression type that matches the type of the original file to be transmitted to the client according to the compression type information; the processing module 12 is used to apply the compression corresponding to the first compression type The algorithm compresses the original file, and sends the compressed file with the first compression type identifier to the client through the TCP socket channel with the client, so that the client application can communicate with the client The compression algorithm corresponding to the first compression type decompresses the compressed file to obtain the original file.

其中,处理模块12具体用于:判断所述原始文件的大小是否大于等于预设的阈值,若是,则应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理,否则,则将所述原始文件移入缓存区,达到预设的缓存时间后,应用与所述第一压缩类型对应的压缩算法对存入缓存区的一个或多个原始文件进行压缩处理。Wherein, the processing module 12 is specifically used to: determine whether the size of the original file is greater than or equal to a preset threshold, if so, apply a compression algorithm corresponding to the first compression type to compress the original file, otherwise, Then move the original files into the cache area, and after the preset cache time is reached, compress the one or more original files stored in the cache area by applying a compression algorithm corresponding to the first compression type.

本实施例提供的支持websocket的服务器中各模块的功能和处理流程,可以参见上述图1所示的方法实施例,其实现原理和技术效果类似,此处不再赘述。For the functions and processing flow of each module in the websocket-supporting server provided by this embodiment, refer to the method embodiment shown in FIG. 1 above. The implementation principles and technical effects are similar, and will not be repeated here.

基于上述实施例,进一步地,所述处理模块12还用于:接收所述客户端发送的包括第二压缩类型的更新请求消息,若判断获知自身支持所述第二压缩类型,则应用与所述第二压缩类型对应的压缩算法对后续待传输给所述客户端的原始文件进行压缩处理。Based on the above embodiment, further, the processing module 12 is further configured to: receive an update request message sent by the client that includes the second compression type, and if it is determined that it supports the second compression type, the application and the The compression algorithm corresponding to the second compression type performs compression processing on the original file to be subsequently transmitted to the client.

图4为本发明实施例提供的一个支持websocket的客户端的结构示意图,如图4所示,该客户端包括:预处理模块21、接收模块22和解压缩模块23,其中,预处理模块21用于与支持websocket的服务器协商所共同支持的压缩类型信息;接收模块22用于通过与所述服务器之间的TCPsocket通道接收应用第一压缩类型标识的压缩文件,其中,所述第一压缩类型是所述服务器根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的压缩类型;解压缩模块23用于应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。Fig. 4 is a schematic structural diagram of a websocket-supporting client provided by an embodiment of the present invention. As shown in Fig. 4, the client includes: a preprocessing module 21, a receiving module 22 and a decompression module 23, wherein the preprocessing module 21 is used for Negotiate the commonly supported compression type information with the server supporting websocket; the receiving module 22 is used to receive the compressed file marked with the first compression type through the TCPsocket channel between the server and the server, wherein the first compression type is the The server determines the compression type matching the type of the original file to be transmitted to the client according to the compression type information; the decompression module 23 is used to apply a compression algorithm corresponding to the first compression type to perform compression on the compressed file A decompression process obtains the original file.

本实施例提供的支持websocket的客户端中各模块的功能和处理流程,可以参见上述图1所示的方法实施例,其实现原理和技术效果类似,此处不再赘述。For the functions and processing flow of each module in the websocket-supporting client provided by this embodiment, refer to the method embodiment shown in FIG. 1 above. The implementation principles and technical effects are similar and will not be repeated here.

图5为本发明实施例提供的一个基于websocket协议的数据传输系统的结构示意图,如图5所示,该系统包括:支持websocket的服务器1和支持websocket的客户端2,其中,支持websocket的服务器1和支持websocket的客户端2可以采用本发明上述实施例提供的支持websocket的服务器和支持websocket的客户端。Figure 5 is a schematic structural diagram of a data transmission system based on the websocket protocol provided by an embodiment of the present invention. As shown in Figure 5, the system includes: a server 1 supporting websocket and a client 2 supporting websocket, wherein the server supporting websocket 1 and the websocket-supporting client 2 can adopt the websocket-supporting server and the websocket-supporting client provided by the above embodiments of the present invention.

本实施例提供的基于websocket协议的数据传输系统中各模块的功能和处理流程,可以参见上述图1所示的方法实施例,其实现原理和技术效果类似,此处不再赘述。For the functions and processing flow of each module in the data transmission system based on the websocket protocol provided in this embodiment, refer to the method embodiment shown in FIG. 1 above. The implementation principle and technical effect are similar, and will not be repeated here.

最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: it can still be Modifications are made to the technical solutions described in the foregoing embodiments, or equivalent replacements are made to some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims (7)

1.一种websocket协议的数据传输方法,其特征在于,包括:1. A data transmission method of websocket protocol, characterized in that, comprising: 支持websocket的服务器与支持websocket的客户端协商所共同支持的压缩类型信息,根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的第一压缩类型;The server that supports websocket negotiates with the client that supports websocket about the commonly supported compression type information, and determines the first compression type that matches the type of the original file to be transmitted to the client according to the compression type information; 所述服务器应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理,并通过与所述客户端之间的TCPsocket通道将应用所述第一压缩类型标识的压缩文件发送给所述客户端,以供所述客户端应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件;The server applies a compression algorithm corresponding to the first compression type to compress the original file, and sends the compressed file identified by the first compression type to the The client is used for the client to apply a compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file; 所述根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的第一压缩类型包括:The determining the first compression type that matches the type of the original file to be transmitted to the client according to the compression type information includes: 服务器查询对应关系获取与待传输给所述客户端的原始文件的类型匹配的第一压缩类型,其中,所述对应关系为服务器本地存储的文件类型与压缩类型的对应关系,所述对应关系是根据不同的压缩类型对应的压缩算法对不同类型的文件进行压缩效率测试所获取的;The server queries the corresponding relationship to obtain the first compression type that matches the type of the original file to be transmitted to the client, wherein the corresponding relationship is the corresponding relationship between the file type and the compressed type stored locally on the server, and the corresponding relationship is based on The compression algorithms corresponding to different compression types are obtained by performing compression efficiency tests on different types of files; 所述应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理包括:The compressing the original file by applying the compression algorithm corresponding to the first compression type includes: 所述服务器判断所述原始文件的大小是否大于等于预设的阈值,若是,则应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理,否则,则将所述原始文件移入缓存区,达到预设的缓存时间后,应用与所述第一压缩类型对应的压缩算法对存入缓存区的一个或多个原始文件进行压缩处理。The server determines whether the size of the original file is greater than or equal to a preset threshold, and if so, applies a compression algorithm corresponding to the first compression type to compress the original file, otherwise, compresses the original file Move into the cache area, and after the preset cache time is reached, compress the one or more original files stored in the cache area by applying a compression algorithm corresponding to the first compression type. 2.根据权利要求1所述的websocket协议的数据传输方法,其特征在于,所述方法还包括:2. the data transmission method of websocket protocol according to claim 1, is characterized in that, described method also comprises: 所述服务器接收所述客户端发送的包括第二压缩类型的更新请求消息,若判断获知自身支持所述第二压缩类型,则应用与所述第二压缩类型对应的压缩算法对后续待传输给所述客户端的原始文件进行压缩处理。The server receives the update request message sent by the client and includes the second compression type, and if it determines that it supports the second compression type, it applies the compression algorithm corresponding to the second compression type to the subsequent The original file of the client is compressed. 3.一种websocket协议的数据传输方法,其特征在于,包括:3. A data transmission method of websocket protocol, characterized in that, comprising: 支持websocket的客户端与支持websocket的服务器协商所共同支持的压缩类型信息;The client that supports websocket negotiates with the server that supports websocket to support the compression type information; 所述客户端通过与所述服务器之间的TCPsocket通道接收应用第一压缩类型标识的压缩文件,其中,所述第一压缩类型是所述服务器查询文件类型与压缩类型的对应关系之后获取的,与待传输给所述客户端的原始文件的类型匹配压缩类型,其中所述对应关系是由所述服务器根据不同的压缩类型对应的压缩算法对不同类型的文件进行压缩效率测试所获得并存储在所述服务器的本地的;The client receives the compressed file identified by the first compression type through the TCP socket channel between the client and the server, wherein the first compression type is obtained after the server inquires about the correspondence between the file type and the compression type, Match the compression type with the type of the original file to be transmitted to the client, wherein the correspondence is obtained by the server performing compression efficiency tests on different types of files according to compression algorithms corresponding to different compression types and stored in the Local to the above server; 所述客户端应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。The client applies a compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file. 4.一种支持websocket的服务器,其特征在于,包括:4. A server supporting websocket, comprising: 匹配模块,用于与支持websocket的客户端协商所共同支持的压缩类型信息,根据所述压缩类型信息确定与待传输给所述客户端的原始文件的类型匹配的第一压缩类型;A matching module, configured to negotiate with the websocket-supporting client on commonly supported compression type information, and determine a first compression type that matches the type of the original file to be transmitted to the client according to the compression type information; 匹配模块具体用于查询对应关系获取与待传输给所述客户端的原始文件的类型匹配的第一压缩类型,其中,所述对应关系为服务器本地存储的文件类型与压缩类型的对应关系,所述对应关系是根据不同的压缩类型对应的压缩算法对不同类型的文件进行压缩效率测试所获取的;The matching module is specifically used to query the corresponding relationship to obtain the first compression type that matches the type of the original file to be transmitted to the client, wherein the corresponding relationship is the corresponding relationship between the file type and the compression type stored locally on the server, and the The corresponding relationship is obtained by performing compression efficiency tests on different types of files according to the compression algorithms corresponding to different compression types; 处理模块,用于应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理,并通过与所述客户端之间的TCPsocket通道将应用所述第一压缩类型标识的压缩文件发送给所述客户端,以供所述客户端应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件;A processing module, configured to apply a compression algorithm corresponding to the first compression type to compress the original file, and compress the compressed file identified by the first compression type through the TCP socket channel with the client sending to the client, so that the client applies a compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file; 所述处理模块具体用于:The processing module is specifically used for: 判断所述原始文件的大小是否大于等于预设的阈值,若是,则应用与所述第一压缩类型对应的压缩算法对所述原始文件进行压缩处理,否则,则将所述原始文件移入缓存区,达到预设的缓存时间后,应用与所述第一压缩类型对应的压缩算法对存入缓存区的一个或多个原始文件进行压缩处理。Judging whether the size of the original file is greater than or equal to a preset threshold, if so, applying the compression algorithm corresponding to the first compression type to compress the original file, otherwise, moving the original file into the cache After the preset cache time is reached, apply the compression algorithm corresponding to the first compression type to compress the one or more original files stored in the cache area. 5.根据权利要求4所述的支持websocket的服务器,其特征在于,所述处理模块还用于:5. the server supporting websocket according to claim 4, is characterized in that, described processing module is also used for: 接收所述客户端发送的包括第二压缩类型的更新请求消息,若判断获知自身支持所述第二压缩类型,则应用与所述第二压缩类型对应的压缩算法对后续待传输给所述客户端的原始文件进行压缩处理。Receive an update request message including the second compression type sent by the client, and if it is determined that it supports the second compression type, apply a compression algorithm corresponding to the second compression type to be transmitted to the client The original file at the end is compressed. 6.一种支持websocket的客户端,其特征在于,包括:6. A client supporting websocket, comprising: 预处理模块,用于与支持websocket的服务器协商所共同支持的压缩类型信息;The preprocessing module is used for negotiating the commonly supported compression type information with the server supporting websocket; 接收模块,用于通过与所述服务器之间的TCPsocket通道接收应用第一压缩类型标识的压缩文件,其中,所述第一压缩类型是所述服务器查询文件类型与压缩类型的对应关系之后获取的,与待传输给所述客户端的原始文件的类型匹配压缩类型,其中所述对应关系是由所述服务器根据不同的压缩类型对应的压缩算法对不同类型的文件进行压缩效率测试所获得并存储在所述服务器的本地的;A receiving module, configured to receive a compressed file marked with a first compression type through a TCP socket channel with the server, wherein the first compression type is obtained after the server inquires about the correspondence between the file type and the compression type , matching the compression type with the type of the original file to be transmitted to the client, wherein the correspondence is obtained by the server performing compression efficiency tests on different types of files according to compression algorithms corresponding to different compression types and stored in local to said server; 解压缩模块,用于应用与所述第一压缩类型对应的压缩算法对所述压缩文件进行解压缩处理获取所述原始文件。A decompression module, configured to apply a compression algorithm corresponding to the first compression type to decompress the compressed file to obtain the original file. 7.一种基于websocket协议的数据传输系统,其特征在于,包括:如权利要求4或5所述的支持websocket的服务器,以及如权利要求6所述的支持websocket的客户端。7. A data transmission system based on the websocket protocol, comprising: the websocket-supporting server as claimed in claim 4 or 5, and the websocket-supporting client as claimed in claim 6.
CN201310535026.1A 2013-11-01 2013-11-01 Data transmission method, device and system of websocket protocol Active CN103532984B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310535026.1A CN103532984B (en) 2013-11-01 2013-11-01 Data transmission method, device and system of websocket protocol

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310535026.1A CN103532984B (en) 2013-11-01 2013-11-01 Data transmission method, device and system of websocket protocol

Publications (2)

Publication Number Publication Date
CN103532984A CN103532984A (en) 2014-01-22
CN103532984B true CN103532984B (en) 2017-02-08

Family

ID=49934663

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310535026.1A Active CN103532984B (en) 2013-11-01 2013-11-01 Data transmission method, device and system of websocket protocol

Country Status (1)

Country Link
CN (1) CN103532984B (en)

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103873860B (en) * 2014-03-18 2017-12-22 深信服网络科技(深圳)有限公司 Document transmission method and device
US9287893B1 (en) * 2015-05-01 2016-03-15 Google Inc. ASIC block for high bandwidth LZ77 decompression
CN106686748B (en) * 2015-11-05 2020-08-07 泰康保险集团股份有限公司 Control method for multi-terminal device communication, terminal device and server
CN106506331B (en) * 2016-10-26 2019-10-22 宁波菊风系统软件有限公司 A kind of text information transmission method of low latency
CN106790462B (en) * 2016-12-08 2019-12-06 东软集团股份有限公司 Short sentence transmission method and system, server, sending client and receiving client
CN110365690A (en) * 2019-07-19 2019-10-22 迈普通信技术股份有限公司 Flow collection method, apparatus and storage medium
CN112311720B (en) * 2019-07-23 2022-10-14 腾讯科技(深圳)有限公司 Data transmission method and device
CN111683189B (en) * 2020-05-14 2023-04-07 苏州达家迎信息技术有限公司 Picture compression method, system, terminal and storage medium
CN114071241A (en) * 2020-08-06 2022-02-18 成都鼎桥通信技术有限公司 Video playing method, system, electronic equipment and storage medium
CN114363379A (en) * 2022-01-19 2022-04-15 北京中交兴路信息科技有限公司 Vehicle data transmission method and device, electronic equipment and medium
CN118502968B (en) * 2024-07-17 2024-12-31 杭州乒乓智能技术有限公司 WebSocket-based data push method, device, computer equipment, and readable storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5742773A (en) * 1996-04-18 1998-04-21 Microsoft Corporation Method and system for audio compression negotiation for multiple channels
CN1471282A (en) * 2002-07-24 2004-01-28 华为技术有限公司 A message transmission method based on multi-protocol label switching network
CN101039261A (en) * 2006-03-16 2007-09-19 华为技术有限公司 Method, system and apparatus for processing user terminal accessing network and loading establishing process
CN101197824A (en) * 2006-12-08 2008-06-11 华为技术有限公司 A method and system for determining a compression algorithm
CN102932844A (en) * 2012-11-28 2013-02-13 北京傲天动联技术有限公司 Method for increasing wireless network communication throughput and network node device
CN102970356A (en) * 2012-11-08 2013-03-13 百度在线网络技术(北京)有限公司 Communication method, system and device for cloud server and client

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5742773A (en) * 1996-04-18 1998-04-21 Microsoft Corporation Method and system for audio compression negotiation for multiple channels
CN1471282A (en) * 2002-07-24 2004-01-28 华为技术有限公司 A message transmission method based on multi-protocol label switching network
CN101039261A (en) * 2006-03-16 2007-09-19 华为技术有限公司 Method, system and apparatus for processing user terminal accessing network and loading establishing process
CN101197824A (en) * 2006-12-08 2008-06-11 华为技术有限公司 A method and system for determining a compression algorithm
CN102970356A (en) * 2012-11-08 2013-03-13 百度在线网络技术(北京)有限公司 Communication method, system and device for cloud server and client
CN102932844A (en) * 2012-11-28 2013-02-13 北京傲天动联技术有限公司 Method for increasing wireless network communication throughput and network node device

Also Published As

Publication number Publication date
CN103532984A (en) 2014-01-22

Similar Documents

Publication Publication Date Title
CN103532984B (en) Data transmission method, device and system of websocket protocol
CN104283723B (en) Network access log processing method and processing device
CN108696899B (en) SIP message transmitting and receiving method and transmitting and receiving device
JP2011512730A5 (en)
JP6250048B2 (en) Data distribution method and data distribution apparatus
CN104954497B (en) Data transmission method and system in a kind of cloud storage system
WO2017114190A1 (en) File uploading processing method and device
CN110866132B (en) Tile map using method suitable for low network bandwidth environment
CN107241417A (en) A kind of method, system, transmitting terminal and the receiving terminal of file transmission
CN103152606B (en) Video file processing method and device, system
EP3258673B1 (en) Efficient information exchange between servers in content transmission network system
WO2022063058A1 (en) Netconf protocol-based transmission method, device and storage medium
CN104767710B (en) The transmission payload extracting method of HTTP block transmissions coding based on DFA
CN105227661A (en) Sharing files method and system, server
CN111669364A (en) A method, device, electronic device and medium for data transmission
CN102982046B (en) A kind of web data compression and storage method and system
CN103929447B (en) A kind of method of the parsing HTTP chunked coded datas based on PEEK operations
CN115604365B (en) Data encoding and decoding method, device, electronic equipment and readable storage medium
CN104780171A (en) Message transferring method, device and system
CN105657451A (en) Method and system for simultaneously uploading video file and transcoding
CN110636374A (en) Method and device for searching information
CN104994088A (en) Data checking method based on WiFi connection, client, server and system
CN102957633A (en) Data packing and transmitting method and data packing and transmitting system for message-oriented middleware
WO2017092350A1 (en) Method and device for improving cache hit ratio
KR101331095B1 (en) compressed transmission method for XML massages based on OMA DM, and system thereof

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant