CN110311936B - Communication method and device between clients, electronic equipment and storage medium - Google Patents
Communication method and device between clients, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN110311936B CN110311936B CN201810257702.6A CN201810257702A CN110311936B CN 110311936 B CN110311936 B CN 110311936B CN 201810257702 A CN201810257702 A CN 201810257702A CN 110311936 B CN110311936 B CN 110311936B
- Authority
- CN
- China
- Prior art keywords
- thread
- client browser
- binary string
- network connection
- network
- 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
Links
- 238000004891 communication Methods 0.000 title claims abstract description 157
- 238000000034 method Methods 0.000 title claims abstract description 57
- 230000007246 mechanism Effects 0.000 claims description 68
- 238000004806 packaging method and process Methods 0.000 claims description 30
- 230000000903 blocking effect Effects 0.000 claims description 10
- 238000005538 encapsulation Methods 0.000 claims description 9
- 230000005540 biological transmission Effects 0.000 abstract description 17
- 238000006243 chemical reaction Methods 0.000 description 6
- 238000010586 diagram Methods 0.000 description 6
- VYZAMTAEIAYCRO-UHFFFAOYSA-N Chromium Chemical compound [Cr] VYZAMTAEIAYCRO-UHFFFAOYSA-N 0.000 description 4
- 241001101720 Murgantia histrionica Species 0.000 description 2
- 238000004590 computer program Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/141—Setup of application sessions
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/161—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
- H04L69/162—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/60—Network structure or processes for video distribution between server and client or between remote clients; Control signalling between clients, server and network components; Transmission of management data between server and client, e.g. sending from server to client commands for recording incoming content stream; Communication details between server and client
- H04N21/63—Control signaling related to video distribution between client, server and network components; Network processes for video distribution between server and clients or between remote clients, e.g. transmitting basic layer and enhancement layers over different transmission paths, setting up a peer-to-peer communication via Internet between remote STB's; Communication protocols; Addressing
- H04N21/643—Communication protocols
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/80—Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
- H04N21/81—Monomedia components thereof
- H04N21/8166—Monomedia components thereof involving executable data, e.g. software
- H04N21/8173—End-user applications, e.g. Web browser, game
Landscapes
- Engineering & Computer Science (AREA)
- Signal Processing (AREA)
- Computer Networks & Wireless Communication (AREA)
- Multimedia (AREA)
- Computer Security & Cryptography (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Information Transfer Between Computers (AREA)
- Computer And Data Communications (AREA)
Abstract
The embodiment of the invention discloses a communication method and device between clients, electronic equipment and a storage medium, which can improve the access capability of a server in a video live broadcast system and the efficiency of data transmission. The method comprises the following steps: the first thread receives the first network connection and distributes the received first network connection to the second thread; the first network connection is a network connection initiated by a client live broadcast application program; the second thread reads a binary string sent by the client live broadcast application program according to the first network connection; the first thread receives a second network connection and distributes the received second network connection to a second thread or a third thread; the second network connection is a network connection initiated by a client browser; and the second thread or the third thread sends the binary string to the client browser so that the client browser performs analysis operation on the binary string. The embodiment of the invention is suitable for a network video live broadcast system.
Description
Technical Field
The invention relates to the technical field of network video live broadcast, in particular to a communication method and device between clients, electronic equipment and a storage medium.
Background
In a network video live broadcast system, a client live broadcast application program and a client browser establish network connection with a server, and a user can watch live broadcast content through the client live broadcast application program or the client browser. The client live application program and the client browser can realize mutual communication through the server.
In the process of implementing the present invention, the inventor finds that, when a client live application program and a client browser establish a network connection with a server, the server needs to create a separate thread for each connection to manage the connection and perform operations such as reading and sending data. Thus, when the number of connections is large, the server also needs to create a corresponding number of threads to manage the connections and process data, which will certainly reduce the access capability of the server and the efficiency of data transmission.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for communication between clients, an electronic device, and a storage medium, which can improve access capability of a server in a live video system and improve data transmission efficiency.
In a first aspect, an embodiment of the present invention provides a communication method between clients, which is applied to a server in a video live broadcast system, and the method includes:
the first thread receives the first network connection and distributes the received first network connection to the second thread; the first thread is a single thread, and the first network connection is network connection initiated by a client live broadcast application program;
the second thread reads a binary string sent by the client live broadcast application program according to the first network connection;
the first thread receives a second network connection and distributes the received second network connection to a second thread or a third thread; the second network connection is a network connection initiated by a client browser;
and the second thread or the third thread sends the binary string to the client browser so that the client browser performs analysis operation on the binary string.
With reference to the first aspect, in a first implementation manner of the first aspect, the sending, by the second thread or the third thread, the binary string to the client browser to enable the client browser to perform a parsing operation on the binary string includes:
if the client browser supports a network socket communication mechanism, establishing network socket connection with the client browser, and transmitting the binary string to the client browser by the second thread or the third thread according to the network socket connection so that the client browser performs analysis operation on the binary string; and both ends of the client browser and the client live broadcast application program are compatible with a binary protocol.
With reference to the first implementation manner of the first aspect, in a second implementation manner of the first aspect, the sending, by the second thread or the third thread, the binary string to the client browser, so that the client browser performs a parsing operation on the binary string, further includes:
if the client browser does not support a network socket communication mechanism, receiving a binary string acquisition request actively initiated by the client browser, and transmitting the binary string to the client browser by the second thread or the third thread according to the binary string acquisition request so that the client browser performs analysis operation on the binary string.
With reference to the first implementation manner of the first aspect, in a third implementation manner of the first aspect, if the client browser supports a web socket communication mechanism, the establishing a web socket connection with the client browser, and the transmitting, by the second thread or the third thread, the binary string to the client browser according to the web socket connection includes:
if the client browser supports a network socket communication mechanism, a script of the client browser calls a network socket interface packaged in a communication interface packaging packet to establish network socket connection, and the second thread or the third thread transmits the binary string to the client browser according to the network socket connection; the communication interface packaging packet is installed in the client browser, and at least a network socket interface is packaged in the communication interface packaging packet.
With reference to the third implementation manner of the first aspect, in a fourth implementation manner of the first aspect, the invoking, by the script of the client browser, a web socket interface encapsulated in a communication interface encapsulation packet to establish a web socket connection includes:
and calling a network socket interface packaged in socket by JavaScript of the client browser to establish network socket connection.
With reference to the second implementation manner of the first aspect, in a fifth implementation manner of the first aspect, if the client browser does not support a web socket communication mechanism, the receiving a binary string obtaining request actively initiated by the client browser, and the transmitting, by the second thread or the third thread, the binary string to the client browser according to the binary string obtaining request includes:
if the client browser does not support a network socket communication mechanism, automatically calling a communication interface supported by the client browser and packaged in a communication interface packaging packet through a script of the client browser to establish network connection; wherein the communication interface encapsulation package is installed in the client browser;
receiving a binary string acquisition request actively initiated by the client browser;
and the second thread or the third thread transmits the binary string to the client browser according to the binary string acquisition request.
With reference to the fifth implementation manner of the first aspect, in a sixth implementation manner of the first aspect, the automatically invoking, by the script of the client browser, a communication interface supported by the client browser and packaged in a communication interface packaging packet to establish a network connection includes:
and calling a long polling interface packaged in socket by JavaScript of the client browser to establish network connection.
With reference to the first aspect, in a seventh implementation manner of the first aspect, the receiving, by the first thread, a first network connection and allocating the received first network connection to the second thread includes:
in the JAVA NIO non-blocking mode, the first thread receives the first network connection and allocates the received first network connection to the second thread.
In a second aspect, an embodiment of the present invention provides a communication device between clients, which is applied to a server in a live video system, where the device includes:
the connection management module is used for receiving the first network connection through the first thread and distributing the received first network connection to the second thread; receiving a second network connection through the first thread, and allocating the received second network connection to a second thread or a third thread; the first thread is a single thread, and the first network connection is network connection initiated by a client live broadcast application program; the second network connection is a network connection initiated by a client browser;
the data processing module is used for reading a binary string sent by the client live broadcast application program through the second thread according to the first network connection; and sending the binary string to the client browser through the second thread or the third thread so that the client browser performs parsing operation on the binary string.
With reference to the second aspect, in a first implementation manner of the second aspect, the data processing module is specifically configured to: if the client browser supports a network socket communication mechanism, establishing network socket connection with the client browser, and transmitting the binary string to the client browser through the second thread or the third thread according to the network socket connection, so that the client browser performs analysis operation on the binary string; and both ends of the client browser and the client live broadcast application program are compatible with a binary protocol.
With reference to the first implementation manner of the second aspect, in a second implementation manner of the second aspect, the data processing module is further specifically configured to: if the client browser does not support a network socket communication mechanism, receiving a binary string acquisition request actively initiated by the client browser, and transmitting the binary string to the client browser through the second thread or the third thread according to the binary string acquisition request, so that the client browser performs analysis operation on the binary string.
With reference to the first implementation manner of the second aspect, in a third implementation manner of the second aspect, the data processing module is specifically configured to: if the client browser supports a network socket communication mechanism, a script of the client browser calls a network socket interface packaged in a communication interface packaging packet to establish network socket connection, and the second thread or the third thread transmits the binary string to the client browser according to the network socket connection; the communication interface packaging packet is installed in the client browser, and at least a network socket interface is packaged in the communication interface packaging packet.
With reference to the third implementation manner of the second aspect, in a fourth implementation manner of the second aspect, the data processing module is specifically configured to: and if the client browser supports a network socket communication mechanism, calling a network socket interface packaged in socket.IO through JavaScript of the client browser to establish network socket connection, and transmitting the binary string to the client browser by the second thread or the third thread according to the network socket connection.
With reference to the second implementation manner of the second aspect, in a fifth implementation manner of the second aspect, the data processing module is specifically configured to: if the client browser does not support a network socket communication mechanism, automatically calling a communication interface supported by the client browser and packaged in a communication interface packaging packet through a script of the client browser to establish network connection, wherein the communication interface packaging packet is installed in the client browser; receiving a binary string acquisition request actively initiated by the client browser; and the second thread or the third thread transmits the binary string to the client browser according to the binary string acquisition request.
With reference to the fifth implementation manner of the second aspect, in a sixth implementation manner of the second aspect, the data processing module is specifically configured to: if the client browser does not support a network socket communication mechanism, calling a long polling interface packaged in socket. Receiving a binary string acquisition request actively initiated by the client browser; and the second thread or the third thread transmits the binary string to the client browser according to the binary string acquisition request.
With reference to the fifth implementation manner of the second aspect, in a seventh implementation manner of the second aspect, the connection management module is specifically configured to: receiving a first network connection through a first thread in a JAVA NIO non-blocking mode, and distributing the received first network connection to a second thread; receiving a second network connection through the first thread, and allocating the received second network connection to a second thread or a third thread; the first thread is a single thread, and the first network connection is network connection initiated by a client live broadcast application program; the second network connection is a network connection initiated by the client browser.
In a third aspect, an embodiment of the present invention provides an electronic device, where the electronic device includes: the device comprises a shell, a processor, a memory, a circuit board and a power circuit, wherein the circuit board is arranged in a space enclosed by the shell, and the processor and the memory are arranged on the circuit board; a power supply circuit for supplying power to each circuit or device of the electronic apparatus; the memory is used for storing executable program codes; the processor reads the executable program code stored in the memory to run a program corresponding to the executable program code, so as to execute any one of the communication methods.
In a fourth aspect, embodiments of the present invention also provide a computer-readable storage medium storing one or more programs, the one or more programs being executable by one or more processors to implement the communication method of any preceding claim.
According to the communication method, the communication device, the electronic equipment and the storage medium between the clients, the first network connection and the second network connection are received through the first thread, the received first network connection is distributed to the second thread, and the second thread reads a binary string sent by a client live broadcast application program according to the first network connection; the first thread distributes the received second network connection to a second thread or a third thread, the second thread or the third thread sends the binary string sent by the second thread reading client live broadcast application program to the client browser, so that the client browser carries out analysis operation on the binary string, thus, a plurality of network connections (a first network connection and a second network connection) can be managed through one single thread (the first thread), specific operations such as reading, sending and the like are handled by other processing threads (the second thread or the third thread), management of the network connections and data operation after connection are separately arranged and are respectively handled by different threads, and therefore the access capability of a server in a video live broadcast system can be improved; furthermore, data sent by the client live application program is a binary string, and data received by the client browser is also a binary string, so that the binary string sent by the client live application program can be directly transmitted to the client browser through the server, and operations such as unpacking or protocol conversion are not required in the process, and the data transmission efficiency is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic flow chart illustrating a communication method between clients according to an embodiment of the present invention;
FIG. 2 is a block diagram illustrating a single thread for managing multiple connections according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating a second thread or a third thread sending a binary string to a client browser according to an embodiment of the present invention;
FIG. 4 is a schematic structural diagram of a communication device between clients according to a second embodiment of the present invention;
fig. 5 is a schematic structural diagram of an embodiment of an electronic device according to the present invention.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
It should be understood that the described embodiments are only some embodiments of the invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment provides a communication method and device between clients, electronic equipment and a storage medium, which are applied to a server in a network video live broadcast system. The client live broadcast application program can be installed on a mobile terminal such as a mobile phone. The client browser can be installed on a desktop computer and can also be installed on mobile terminals such as mobile phones. The user can watch the live broadcast content through a client live broadcast application program on the mobile terminal and can also watch the live broadcast content through a client browser. The client live application program and the client browser can realize mutual communication through the server.
Fig. 1 is a schematic flow chart of a communication method between clients according to an embodiment of the present invention, and referring to fig. 1, the method of the present embodiment is applied to a server in a network video live broadcast system, and the method may include:
The first thread is a single thread for managing a plurality of network connections. The second thread is a business processing thread which specifically processes reading, sending and other operations. The first thread and the second thread can communicate by means of wait, notify and the like. The first network connection is a network connection initiated by a client live broadcast application program. The first thread may allocate the received first network connection to a queue of the second thread, facilitating the second thread to obtain the first network connection from its queue.
Fig. 2 is a schematic structural diagram illustrating a structure of managing multiple connections through a single thread according to an embodiment of the present invention. Referring to fig. 2, both the client live application and the client browser can access the server of the live system through the first thread, and the specific operations of reading, sending, and the like are completed by other service processing threads, such as the second thread, the third thread, and the like. Because the number of people online at the same time of the live video application is possibly large, in the embodiment, a JAVA NIO non-blocking mode is adopted to realize that the client live application program and the client browser efficiently access to the server of the live broadcast system. JAVA NIO is an abbreviation of JAVA New IO, and is a New API (Application Programming Interface) provided in jdk 1.4. The non-blocking mode of Java NIO can manage a plurality of network connections by using a single thread, and the specific operations of reading, sending and the like are completed by other service processing threads, so that the Java NIO non-blocking mode is adopted to realize that a client live broadcast application program and a client browser are efficiently accessed into a server of a live broadcast system, the access capability of the server can be improved, and the server can effectively bear the establishment of a large number of connections and data transmission work. The plurality of network connections comprise network connections of the client live broadcast application programs and network connections of the client browsers, wherein the number of the network connections of the client live broadcast application programs can be multiple, and the number of the network connections of the client browsers can also be multiple.
And 102, reading a binary string sent by the client live broadcast application program by the second thread according to the first network connection.
The first thread receives the first network connection, and the first network connection can be established between the client live broadcast application program and the server. In order to realize efficient data transmission between the client live broadcast application program and the client browser, both ends of the client live broadcast application program and the client browser are compatible with a binary protocol. After the client live broadcast application program establishes first network connection with the server, the client live broadcast application program can serialize data objects to be transmitted into binary strings and transmit the binary strings, and the second thread reads the binary strings transmitted by the client live broadcast application program according to the first network connection.
And 103, the first thread receives a second network connection and distributes the received second network connection to the second thread or a third thread.
The second network connection is a network connection initiated by the client browser. The client browser may be an IE browser, Google Chrome or firefox browser, etc.
And the first thread receives the second network connection, namely the second network connection can be established between the client browser and the server.
The first thread may assign the received second network connection directly to the second thread, through which the binary string is sent to the client browser. In another embodiment, the first thread may also allocate the received second network connection to other business processing threads other than the second thread, for example, to a third thread, and specifically, the first thread may first store the read binary string in a buffer, and after receiving the second network connection, the first thread may allocate the second network connection to the third thread, and the third thread reads the binary string from the buffer and sends the binary string to the client browser.
And 104, the second thread or the third thread sends the binary string to the client browser, so that the client browser performs analysis operation on the binary string.
According to the communication method between the clients, the first network connection and the second network connection are received through the first thread, the received first network connection is distributed to the second thread, and the second thread reads a binary string sent by a client live broadcast application program according to the first network connection; the first thread distributes the received second network connection to a second thread or a third thread, the second thread or the third thread sends the binary string sent by the second thread reading client live broadcast application program to the client browser, so that the client browser carries out analysis operation on the binary string, thus, a plurality of network connections (a first network connection and a second network connection) can be managed through one single thread (the first thread), specific operations such as reading, sending and the like are handled by other processing threads (the second thread or the third thread), management of the network connections and data operation after connection are separately arranged and are respectively handled by different threads, and therefore the access capability of a server in a video live broadcast system can be improved; furthermore, data sent by the client live application program is a binary string, and data received by the client browser is also a binary string, so that the binary string sent by the client live application program can be directly transmitted to the client browser through the server, and operations such as unpacking or protocol conversion are not required in the process, and the data transmission efficiency is improved.
Fig. 3 is a flowchart illustrating a process of sending a binary string to a client browser by a second thread or a third thread according to an embodiment of the present invention. Referring to fig. 3, according to an embodiment of the present invention, the second thread or the third thread sends the binary string to the client browser, so that the client browser performs a parsing operation on the binary string (step 104), which may include:
WebSocket is a protocol that HTML5 initially provides for full-duplex communication over a single TCP connection. The method is mainly characterized in that the server can actively push information to the client, and the client can also actively send the information to the server.
Because some client browsers may not support the WebSockets communication mechanism, in order to be compatible with different client browsers, especially some low-version browsers, the binary string is sent to the client browser in a corresponding communication manner according to a communication protocol supported by the client browser, and it is necessary to determine whether the client browser supports the WebSocket communication mechanism before the second thread or the third thread sends the binary string to the client browser. If the WebSocket communication mechanism is supported, the WebSocket communication mechanism can be directly adopted for communication, and if the WebSocket communication mechanism is not supported, the communication is automatically degraded to the communication mechanisms such as long polling and the like supported by the low-version browser for communication.
The method for judging whether the client browser supports the WebSocket communication mechanism can detect whether the browser supports WebSocks or not through a browser console (such as Firebug or Chrome development tool), and if not, the WebSocket command returns 'undefined'.
By the judgment, if the client browser supports the WebSocket communication mechanism, executing step 1042, otherwise executing step 1044.
And 1042, establishing a WebSocket connection with the client browser.
In this embodiment, if the client browser supports the WebSocket communication mechanism, the script of the client browser may call the WebSocket interface encapsulated in the communication interface encapsulation package to establish the WebSocket connection.
The communication interface packaging packet is installed in the client browser, and at least a network socket interface is packaged in the communication interface packaging packet. Therefore, if the client browser supports the WebSocket communication mechanism, the network socket interface packaged in the communication interface packaging packet can be directly adopted, and the WebSocket connection can be established quickly.
In an embodiment of the present invention, if the client browser supports a WebSocket communication mechanism, a WebSocket interface packaged in socket. The socket.IO is a communication interface packaging packet which is installed in the client browser, and interfaces of various communication mechanisms such as Websocket, Long Polling (Long Polling) and Flashsocket are packaged in the socket.IO, so that the communication mechanisms such as Websocket, Long Polling and Flashsocket are supported.
In this embodiment, if the client browser supports a WebSocket communication mechanism, the JavaScript of the client browser calls a WebSocket interface encapsulated in socket.
After the WebSocket connection is established between the server and the client browser, if the second thread reads the binary string from the client live broadcast application program, the server does not need to generate the binary string to the client browser after receiving a binary string acquisition request sent by the client browser, but can directly generate the binary string to the client browser, so that the data transmission efficiency can be improved.
Furthermore, both ends of the client live broadcast application program and the client browser are compatible with binary protocols, the client live broadcast application program can organize data packets only by serializing data to be sent, and the client browser can obtain the data packets only by deserializing received binary strings, so that conversion work of protocols due to the fact that the protocols at both ends are different can be avoided, and data transmission efficiency can be further improved.
If the client browser does not support the WebSocket communication mechanism, a long polling communication mechanism can be adopted, and under the long polling communication mechanism, the client browser can actively initiate a binary string acquisition request to the server. And under the condition that the client browser does not actively initiate the binary string acquisition request, the server does not actively transmit the binary string to the client browser.
And 1045, the second thread or the third thread transmits the binary string to the client browser according to the binary string acquisition request.
And the server transmits the binary string to the client browser according to the binary string acquisition request. Specifically, the binary string may be transmitted to the client browser through the second thread or the third thread according to the binary string acquisition request, so that the client browser performs a parsing operation on the binary string.
In this embodiment, if the client browser does not support the WebSocket communication mechanism, the server waits for receiving a binary string acquisition request actively initiated by the client browser, and the server transmits the binary string to the client browser according to the binary string acquisition request, so that the client browser performs an analysis operation on the binary string, thereby ensuring that data transmission can be performed normally even if the client browser does not support the WebSocket communication mechanism.
Specifically, if the client browser does not support the WebSocket communication mechanism, a script of the client browser automatically calls a communication interface supported by the client browser, such as a long connection interface, packaged in a communication interface packaging packet to establish a network connection.
In this embodiment, a plurality of communication interfaces are encapsulated in the communication interface encapsulation packet, and if the client browser does not support the WebSocket communication mechanism, the communication interface supported by the client browser may be automatically used to establish a network connection, for example, the long connection interface supported by the low-version browser may be automatically used to establish a network connection, so that different browsers may be better compatible to implement network communication.
Further, if the client browser does not support the WebSocket communication mechanism, the JavaScript of the client browser can call the long polling interface encapsulated in socket.
Fig. 4 is a schematic structural diagram of a communication device between clients according to an embodiment of the present invention, and referring to fig. 4, the device of the present embodiment is applied to a server in a network video live broadcast system, and the device may include: a connection management module 11 and a data processing module 12.
A connection management module 11, configured to receive a first network connection through a first thread, and allocate the received first network connection to a second thread; receiving a second network connection through the first thread, and allocating the received second network connection to a second thread or a third thread; the first thread is a single thread, and the first network connection is network connection initiated by a client live broadcast application program; the second network connection is a network connection initiated by the client browser.
The first thread is a single thread for managing a plurality of network connections. The second thread is a business processing thread which specifically processes reading, sending and other operations. The first thread and the second thread can communicate by means of wait, notify and the like. The first network connection is a network connection initiated by a client live broadcast application program. The first thread may allocate the received first network connection to a queue of the second thread, facilitating the second thread to obtain the first network connection from its queue.
Both the client live broadcast application program and the client browser can access a server of the live broadcast system. In this embodiment, a JAVA NIO non-blocking mode is used to implement that the client live application and the client browser efficiently access to the server of the live system. JAVA NIO is an abbreviation of JAVA New IO, and is a New API (Application Programming Interface) provided in jdk 1.4. The non-blocking mode of Java NIO can manage multiple network connections by using a single thread, and the specific operations of reading, sending, and the like are completed by other service processing threads, so in this embodiment, the Java NIO non-blocking mode is used to implement that the client live broadcast application program and the client browser efficiently access to the server of the live broadcast system, which can improve the access capability of the server, and enable the server to effectively carry a large number of connections for establishment and data transmission. The plurality of network connections comprise network connections of the client live broadcast application programs and network connections of the client browsers, wherein the number of the network connections of the client live broadcast application programs can be multiple, and the number of the network connections of the client browsers can also be multiple.
The second network connection is a network connection initiated by the client browser. The client browser may be an IE browser, Google Chrome or firefox browser, etc.
And the first thread receives the second network connection, namely the second network connection can be established between the client browser and the server. The first thread may assign the received second network connection directly to the second thread, through which the binary string is sent to the client browser. In another embodiment, the first thread may also allocate the received second network connection to other business processing threads other than the second thread, for example, to a third thread, and specifically, the first thread may first store the read binary string in a buffer, and after receiving the second network connection, the first thread may allocate the second network connection to the third thread, and the third thread reads the binary string from the buffer and sends the binary string to the client browser.
The data processing module 12 is configured to read, by the second thread according to the first network connection, a binary string sent by the client live broadcast application program; and sending the binary string to the client browser through the second thread or the third thread so that the client browser performs parsing operation on the binary string.
As described above, in this embodiment, both ends of the client live application and the client browser are compatible with the binary protocol. When the client live application program communicates with the two ends of the client browser through the server, the server can directly transmit the binary string sent by the client live application program to the client browser, data transmission can be completed without unpacking processing or data conversion, and transmission efficiency is effectively improved.
According to an embodiment of the present invention, the data processing module 12 is specifically configured to: if the client browser supports a WebSocket communication mechanism, establishing network socket connection with the client browser, and transmitting the binary string to the client browser through the second thread or the third thread according to the network socket connection, so that the client browser performs analysis operation on the binary string; and both ends of the client browser and the client live broadcast application program are compatible with a binary protocol.
WebSocket is a protocol originally provided by HTML5 for full-duplex communication over a single TCP connection. The method is mainly characterized in that the server can actively push information to the client, and the client can also actively send the information to the server.
After the WebSocket connection is established between the server and the client browser, if the second thread reads the binary string from the client live broadcast application program, the server does not need to generate the binary string to the client browser after receiving a binary string acquisition request sent by the client browser, but can directly generate the binary string to the client browser, so that the data transmission efficiency can be improved.
Furthermore, both ends of the client live broadcast application program and the client browser are compatible with binary protocols, the client live broadcast application program can organize data packets only by serializing data to be sent, and the client browser can obtain the data packets only by deserializing received binary strings, so that conversion work of protocols due to the fact that the protocols at both ends are different can be avoided, and data transmission efficiency can be further improved.
If the client browser supports a network socket communication mechanism, a script of the client browser calls a network socket interface packaged in a communication interface packaging packet to establish network socket connection, and the second thread or the third thread transmits the binary string to the client browser according to the network socket connection; the communication interface packaging packet is installed in the client browser, and at least a network socket interface is packaged in the communication interface packaging packet. Therefore, if the client browser supports the WebSocket communication mechanism, the network socket interface packaged in the communication interface packaging packet can be directly adopted, and the WebSocket connection can be established quickly.
In an embodiment of the present invention, if the client browser supports a WebSocket communication mechanism, a WebSocket interface packaged in socket. And the second thread or the third thread transmits the binary string to the client browser according to the Websocket connection.
The socket.IO is used as a communication interface packaging packet and installed in the client browser, and interfaces of various communication mechanisms such as Websocket, Long Polling (Long Polling) and Flashsocket are packaged in the socket.IO, so that the communication mechanisms such as Websocket, Long Polling and Flashsocket are supported.
In this embodiment, if the client browser supports a WebSocket communication mechanism, the JavaScript of the client browser calls a WebSocket interface encapsulated in socket.
Since some client browsers may not support the WebSocket communication mechanism, in order to be compatible with different client browsers, the binary string is sent to the client browser in a corresponding communication manner according to a communication protocol supported by the client browser, and it is necessary to determine whether the client browser supports the WebSocket communication mechanism before the second thread or the third thread sends the binary string to the client browser. If the WebSocket communication mechanism is supported, the WebSocket communication mechanism can be directly adopted for communication, and if the WebSocket communication mechanism is not supported, the communication is automatically degraded to the communication mechanisms such as long polling and the like supported by the low-version browser for communication.
The method for judging whether the client browser supports the WebSocket communication mechanism can detect whether the browser supports WebSocks or not through a browser console (such as Firebug or Chrome development tool), and if not, the WebSocket command returns 'undefined'.
According to an embodiment of the present invention, the data processing module 12 is further specifically configured to: if the client browser does not support the network socket communication mechanism, receiving a binary string acquisition request actively initiated by the client browser, and transmitting the binary string to the client browser through the second thread or the third thread according to the binary string acquisition request, so that the client browser performs analysis operation on the binary string, and data transmission can be performed normally under the condition that the client browser does not support the Websocket communication mechanism.
In this embodiment, if the client browser does not support the WebSocket communication mechanism, the data processing module automatically calls, through a script of the client browser, a communication interface supported by the client browser and encapsulated in a communication interface encapsulation package to establish a network connection, where the communication interface encapsulation package is installed in the client browser; receiving a binary string acquisition request actively initiated by the client browser; and the second thread or the third thread transmits the binary string to the client browser according to the binary string acquisition request, so that if the client browser does not support a WebSocket communication mechanism, a communication interface supported by the client browser packaged in the communication interface packaging packet can be directly adopted to establish network connection, and the rapid establishment of the network connection is facilitated.
In an embodiment of the present invention, if the client browser does not support the web socket communication mechanism, a long polling communication mechanism may be used to establish a network connection between the server and the client browser, and under the long polling communication mechanism, the client browser may actively initiate a binary string acquisition request to the server. And under the condition that the client browser does not actively initiate the binary string acquisition request, the server does not actively transmit the binary string to the client browser.
In an embodiment of the present invention, the data processing module calls a long polling interface encapsulated in socket.io through JavaScript of the client browser to establish a network connection. Therefore, the long connection can be established based on the existing socket.
In the communication device between clients provided by the embodiment of the present invention, the connection management module receives the first network connection and the second network connection through the first thread, allocates the received first network connection to the second thread, and allocates the received second network connection to the second thread or the third thread; the data processing module reads a binary string sent by a client live application program through the second thread according to the first network connection, and sends the binary string to the client browser through the second thread or the third thread so that the client browser performs analysis operation on the binary string, so that a plurality of network connections (a first network connection and a second network connection) can be managed through one single thread (a first thread), specific operations such as reading and sending are handled by other processing threads (the second thread or the third thread), management of the network connections and data operation after connection are separately arranged and processed by different threads, and accordingly the live broadcast access capability of a server in the video system can be improved; furthermore, data sent by the client live application program is a binary string, and data received by the client browser is also a binary string, so that the binary string sent by the client live application program can be directly transmitted to the client browser through the server, and operations such as unpacking or protocol conversion are not required in the process, and the data transmission efficiency is improved.
An embodiment of the present invention further provides an electronic device, fig. 5 is a schematic structural diagram of an embodiment of the electronic device of the present invention, and a flow of the embodiment shown in fig. 1 of the present invention may be implemented, as shown in fig. 5, where the electronic device may include: the device comprises a shell 41, a processor 42, a memory 43, a circuit board 44 and a power circuit 45, wherein the circuit board 44 is arranged inside a space enclosed by the shell 41, and the processor 42 and the memory 43 are arranged on the circuit board 44; a power supply circuit 45 for supplying power to each circuit or device of the electronic apparatus; the memory 43 is used for storing executable program code; the processor 42 reads the executable program code stored in the memory 43 to execute a program corresponding to the executable program code, so as to execute the communication method according to any of the foregoing embodiments.
For the specific execution process of the above steps by the processor 42 and the steps further executed by the processor 42 by running the executable program code, reference may be made to the description of the method embodiment of the present invention, which is not described herein again.
The electronic device exists in various forms, including but not limited to a server, the server is a device for providing computing services, the server is composed of a processor, a hard disk, a memory, a system bus and the like, the server is similar to a general computer architecture, but the server needs to provide highly reliable services, so that the requirements on processing capacity, stability, reliability, safety, expandability, manageability and the like are high.
Embodiments of the present invention further provide a computer-readable storage medium, where one or more programs are stored, and the one or more programs are executable by one or more processors to implement the communication method provided in any of the foregoing embodiments.
Embodiments of the present invention also provide an application program, which is executed to implement the method provided in any of the embodiments of the present invention.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments.
In particular, as for the apparatus embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
For convenience of description, the above devices are described separately in terms of functional division into various units/modules. Of course, the functionality of the units/modules may be implemented in one or more software and/or hardware implementations of the invention.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims (18)
1. A communication method between clients is applied to a server in a video live broadcast system, and is characterized in that the method comprises the following steps:
the first thread receives the first network connection and distributes the received first network connection to the second thread; the first thread is a single thread, and the first network connection is network connection initiated by a client live broadcast application program;
the second thread reads a binary string sent by the client live broadcast application program according to the first network connection;
the first thread receives a second network connection and distributes the received second network connection to a second thread or a third thread; the second network connection is a network connection initiated by a client browser;
and the second thread or the third thread sends the binary string to the client browser so that the client browser performs analysis operation on the binary string.
2. The method of claim 1, wherein the second thread or a third thread sends the binary string to the client browser to cause the client browser to perform a parsing operation on the binary string, comprising:
if the client browser supports a network socket communication mechanism, establishing network socket connection with the client browser, and transmitting the binary string to the client browser by the second thread or the third thread according to the network socket connection so that the client browser performs analysis operation on the binary string; and both ends of the client browser and the client live broadcast application program are compatible with a binary protocol.
3. The method of claim 2, wherein the second thread or a third thread sends the binary string to the client browser to cause the client browser to perform a parsing operation on the binary string, further comprising:
if the client browser does not support a network socket communication mechanism, receiving a binary string acquisition request actively initiated by the client browser, and transmitting the binary string to the client browser by the second thread or the third thread according to the binary string acquisition request so that the client browser performs analysis operation on the binary string.
4. The method of claim 2, wherein the establishing a web socket connection with the client browser if the client browser supports a web socket communication mechanism, and the second thread or the third thread transmitting the binary string to the client browser according to the web socket connection comprises:
if the client browser supports a network socket communication mechanism, a script of the client browser calls a network socket interface packaged in a communication interface packaging packet to establish network socket connection, and the second thread or the third thread transmits the binary string to the client browser according to the network socket connection; the communication interface packaging packet is installed in the client browser, and at least a network socket interface is packaged in the communication interface packaging packet.
5. The method according to claim 4, wherein the establishing the web socket connection by the script of the client browser calling the web socket interface encapsulated in the communication interface encapsulation packet comprises:
and calling a network socket interface packaged in socket by JavaScript of the client browser to establish network socket connection.
6. The method according to claim 3, wherein the receiving a binary string get request actively initiated by the client browser if the client browser does not support the web socket communication mechanism, and the second thread or the third thread passing the binary string to the client browser according to the binary string get request comprises:
if the client browser does not support a network socket communication mechanism, automatically calling a communication interface supported by the client browser and packaged in a communication interface packaging packet through a script of the client browser to establish network connection; wherein the communication interface encapsulation package is installed in the client browser;
receiving a binary string acquisition request actively initiated by the client browser;
and the second thread or the third thread transmits the binary string to the client browser according to the binary string acquisition request.
7. The method according to claim 6, wherein the automatically invoking, by the script of the client browser, the communication interface supported by the client browser encapsulated in the communication interface encapsulation package to establish the network connection comprises:
and calling a long polling interface packaged in socket by JavaScript of the client browser to establish network connection.
8. The method of claim 1, wherein the first thread receiving a first network connection and assigning the received first network connection to a second thread comprises:
in the JAVA NIO non-blocking mode, the first thread receives the first network connection and allocates the received first network connection to the second thread.
9. A communication device between clients is applied to a server in a video live broadcast system, and is characterized in that the device comprises:
the connection management module is used for receiving the first network connection through the first thread and distributing the received first network connection to the second thread; receiving a second network connection through the first thread, and allocating the received second network connection to a second thread or a third thread; the first thread is a single thread, and the first network connection is network connection initiated by a client live broadcast application program; the second network connection is a network connection initiated by a client browser;
the data processing module is used for reading a binary string sent by the client live broadcast application program through the second thread according to the first network connection; and sending the binary string to the client browser through the second thread or the third thread so that the client browser performs parsing operation on the binary string.
10. The apparatus according to claim 9, wherein the data processing module is specifically configured to: if the client browser supports a network socket communication mechanism, establishing network socket connection with the client browser, and transmitting the binary string to the client browser through the second thread or the third thread according to the network socket connection, so that the client browser performs analysis operation on the binary string; and both ends of the client browser and the client live broadcast application program are compatible with a binary protocol.
11. The apparatus of claim 10, wherein the data processing module is further specifically configured to: if the client browser does not support a network socket communication mechanism, receiving a binary string acquisition request actively initiated by the client browser, and transmitting the binary string to the client browser through the second thread or the third thread according to the binary string acquisition request, so that the client browser performs analysis operation on the binary string.
12. The apparatus according to claim 10, wherein the data processing module is specifically configured to: if the client browser supports a network socket communication mechanism, a script of the client browser calls a network socket interface packaged in a communication interface packaging packet to establish network socket connection, and the second thread or the third thread transmits the binary string to the client browser according to the network socket connection; the communication interface packaging packet is installed in the client browser, and at least a network socket interface is packaged in the communication interface packaging packet.
13. The apparatus according to claim 12, wherein the data processing module is specifically configured to: and if the client browser supports a network socket communication mechanism, calling a network socket interface packaged in socket.IO through JavaScript of the client browser to establish network socket connection, and transmitting the binary string to the client browser by the second thread or the third thread according to the network socket connection.
14. The apparatus according to claim 11, wherein the data processing module is specifically configured to: if the client browser does not support a network socket communication mechanism, automatically calling a communication interface supported by the client browser and packaged in a communication interface packaging packet through a script of the client browser to establish network connection, wherein the communication interface packaging packet is installed in the client browser; receiving a binary string acquisition request actively initiated by the client browser; and the second thread or the third thread transmits the binary string to the client browser according to the binary string acquisition request.
15. The apparatus according to claim 14, wherein the data processing module is specifically configured to: if the client browser does not support a network socket communication mechanism, calling a long polling interface packaged in socket. Receiving a binary string acquisition request actively initiated by the client browser; and the second thread or the third thread transmits the binary string to the client browser according to the binary string acquisition request.
16. The apparatus according to claim 14, wherein the connection management module is specifically configured to: receiving a first network connection through a first thread in a JAVA NIO non-blocking mode, and distributing the received first network connection to a second thread; receiving a second network connection through the first thread, and allocating the received second network connection to a second thread or a third thread; the first thread is a single thread, and the first network connection is network connection initiated by a client live broadcast application program; the second network connection is a network connection initiated by the client browser.
17. An electronic device, characterized in that the electronic device comprises: the device comprises a shell, a processor, a memory, a circuit board and a power circuit, wherein the circuit board is arranged in a space enclosed by the shell, and the processor and the memory are arranged on the circuit board; a power supply circuit for supplying power to each circuit or device of the electronic apparatus; the memory is used for storing executable program codes; the processor reads the executable program code stored in the memory to run the program corresponding to the executable program code, and is used for executing the communication method of any one of the preceding claims.
18. A computer-readable storage medium, storing one or more programs, the one or more programs being executable by one or more processors to implement the communication method of any preceding claim.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810257702.6A CN110311936B (en) | 2018-03-27 | 2018-03-27 | Communication method and device between clients, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810257702.6A CN110311936B (en) | 2018-03-27 | 2018-03-27 | Communication method and device between clients, electronic equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110311936A CN110311936A (en) | 2019-10-08 |
CN110311936B true CN110311936B (en) | 2022-01-07 |
Family
ID=68074164
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810257702.6A Active CN110311936B (en) | 2018-03-27 | 2018-03-27 | Communication method and device between clients, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110311936B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114006898A (en) * | 2021-10-30 | 2022-02-01 | 杭州迪普信息技术有限公司 | Version changing method, device and system |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9459936B2 (en) * | 2009-05-01 | 2016-10-04 | Kaazing Corporation | Enterprise client-server system and methods of providing web application support through distributed emulation of websocket communications |
CN105141567B (en) * | 2014-05-26 | 2019-03-01 | 腾讯科技(深圳)有限公司 | Interaction data processing method and system, the exchange method of terminal applies and server-side |
CN106027487B (en) * | 2016-04-28 | 2019-07-23 | 广州广电运通金融电子股份有限公司 | A kind of access management method and system of hardware device |
CN106997307A (en) * | 2017-02-13 | 2017-08-01 | 上海大学 | A kind of Socket thread pool design methods towards multiple terminals radio communication |
-
2018
- 2018-03-27 CN CN201810257702.6A patent/CN110311936B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN110311936A (en) | 2019-10-08 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8819698B2 (en) | Cross-platform web-based native device feature access | |
CN108494817B (en) | Data transmission method, related device and system | |
CN109815107B (en) | Method and device for automatic testing | |
CN105897888B (en) | Client connection method and system | |
CN114124929A (en) | Cross-network data processing method and device | |
CN102420805A (en) | Method, system and equipment for communication through socket connection | |
CN112954717A (en) | Household appliance network distribution method and device based on H5 page | |
CN113300854A (en) | Edge node capability expansion method, system and expansion box | |
CN112306851A (en) | Automatic testing method and device | |
CN112104679B (en) | Method, apparatus, device and medium for processing hypertext transfer protocol request | |
CN108600378B (en) | File downloading method, device, terminal and storage medium | |
CN112835632B (en) | Method and equipment for calling end capability and computer storage medium | |
CN113965628A (en) | Message scheduling method, server and storage medium | |
CN108600377A (en) | A kind of pause method of file download, device, terminal and storage medium | |
CN110311936B (en) | Communication method and device between clients, electronic equipment and storage medium | |
CN114244654A (en) | URL forwarding method, device, equipment and computer storage medium | |
CN114979295A (en) | Gateway management method and device | |
CN113992641A (en) | Data processing method, device, equipment and storage medium | |
CN108021459B (en) | Method and device for sending dotting logs across processes | |
CN113835789A (en) | Rendering method, rendering device, electronic equipment and computer storage medium | |
CN112738181A (en) | Method, device and server for cluster external IP access | |
CN112650710A (en) | Data migration sending method and device, storage medium and electronic device | |
CN111796906A (en) | Container management method, device, equipment and storage medium | |
CN113779122B (en) | Method and device for exporting data | |
CN111477229B (en) | Voice recognition request processing method and device |
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 | ||
TA01 | Transfer of patent application right | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20210601 Address after: 25, 5th floor, shuangjingfang office building, 3 frisha street, Singapore Applicant after: Zhuomi Private Ltd. Address before: Room 1101, Santai Commercial Building, 139 Connaught Road, Hong Kong, China Applicant before: HONG KONG LIVE.ME Corp.,Ltd. |
|
GR01 | Patent grant | ||
GR01 | Patent grant |