CN110896493B - Bullet screen linking method and mobile terminal - Google Patents

Bullet screen linking method and mobile terminal Download PDF

Info

Publication number
CN110896493B
CN110896493B CN201811067037.0A CN201811067037A CN110896493B CN 110896493 B CN110896493 B CN 110896493B CN 201811067037 A CN201811067037 A CN 201811067037A CN 110896493 B CN110896493 B CN 110896493B
Authority
CN
China
Prior art keywords
socket
creating
event
network
bullet screen
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
CN201811067037.0A
Other languages
Chinese (zh)
Other versions
CN110896493A (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.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201811067037.0A priority Critical patent/CN110896493B/en
Publication of CN110896493A publication Critical patent/CN110896493A/en
Application granted granted Critical
Publication of CN110896493B publication Critical patent/CN110896493B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/20Servers specifically adapted for the distribution of content, e.g. VOD servers; Operations thereof
    • H04N21/25Management operations performed by the server for facilitating the content distribution or administrating data related to end-users or client devices, e.g. end-user or client device authentication, learning user preferences for recommending movies
    • H04N21/254Management at additional data server, e.g. shopping server, rights management server
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/40Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
    • H04N21/47End-user applications
    • H04N21/488Data services, e.g. news ticker
    • H04N21/4884Data services, e.g. news ticker for displaying subtitles
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/80Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
    • H04N21/85Assembly of content; Generation of multimedia applications
    • H04N21/858Linking data to content, e.g. by linking an URL to a video object, by creating a hotspot
    • H04N21/8586Linking data to content, e.g. by linking an URL to a video object, by creating a hotspot by using a URL

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Databases & Information Systems (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention discloses a method for linking barrage and a mobile terminal, which are used for optimizing the process of linking the barrage and improving the efficiency of linking the barrage. The method comprises the following steps: creating related data of the socket and linking the related data with the bullet screen server; determining a network interrupt object socket breaker, wherein the socket breaker is used for triggering socket to interrupt the current link; creating a selection object select of the network, wherein the select is used for monitoring the state information of the socket; creating an event object event for notifying the state information of the socket; creating a Thread object Thread of socket and an execution function void __ RunThread (), which executes Thread; creating a while loop in an execution function to monitor the state of the socket; reading data sent by a bullet screen server received in a socket; and sending the data to be sent to the bullet screen server through the socket.

Description

Bullet screen linking method and mobile terminal
Technical Field
The invention relates to the field of terminals, in particular to a method for linking a bullet screen and a mobile terminal.
Background
With the rapid development of the internet technology, the functions of the mobile terminal are more and more abundant, and the barrage function for improving the user experience also appears on the mobile terminal.
In the conventional scheme, a pop-up screen scheme of a Personal Computer (PC) client is generally migrated to a mobile terminal. For the mobile terminal, the characteristics are that the network is unstable, a mobile 4G network is used, and the mobile terminal can move, for example, the mobile terminal moves to a place where the network signal is not good; or, switching from the 3G network to the 4G network; or, switching from the 4G network to a wireless fidelity (WIFI) network; or switching from WIFI to a 4G network, etc. Meanwhile, for the barrage link, due to various reasons of the client or account, the server may determine the validity of the client during the link, so as to return an error code and the like, and therefore the client needs to consider the error code of the server.
In the conventional scheme, for the bullet screen connection of the client of the mobile terminal to the server, only the usability of the function is considered, and the characteristics of the mobile terminal, such as unstable network, power consumption of the mobile terminal, heat generation and the like, are not considered. Therefore, the connection between the mobile terminal and the bullet screen server is easily interrupted, and the process of restoring the connection is slow.
Disclosure of Invention
The embodiment of the invention provides a method for linking bullet screens and a mobile terminal, which are used for optimizing the process of linking bullet screens and improving the processing efficiency of linking bullet screens.
A first aspect of an embodiment of the present invention provides a method for linking bullet screens, including: creating related data of the socket and linking the related data with the bullet screen server; determining a network interrupt object socket breaker, wherein the socket breaker is used for triggering the socket to interrupt the current link; creating a selection object select of a network, wherein the select is used for monitoring the state information of the socket; creating an event object event, wherein the event is used for notifying the state information of the socket; creating a Thread object Thread of the socket and an execution function void __ RunThread (), wherein the Thread object Thread executes the Thread; creating while loop in the execution function to monitor the state of the socket; reading data sent by the bullet screen server and received in the socket; and sending the data to be sent to the bullet screen server through the socket.
In one possible embodiment, the creating the Thread object Thread of the socket and the executing function void __ RunThread () of executing the Thread include: creating a Thread object Thread of the socket; creating an execution function void __ RunThread (), wherein the execution function void __ RunThread () is used for executing the Thread; and binding a preset basic library Boost with the void __ RunThread (), and transferring the Boost to the void __ RunThread ().
In one possible embodiment, the creating an event object event, where the event is used to notify the socket of the status information includes: creating an event.OnError (ConnectTimeouther) for the event object event, the event.OnError (ConnectTimeouther) to indicate a link timeout error; creating an event.OnError (ConnectionError) of the event object for calling OnError to notify the Socket of an error; creating an event.OnConnect () of the event object, the event.OnConnect () being used to notify the socket link success.
In a possible embodiment, the creating a selection object of the network, the selection object being used for monitoring the state information of the socket, includes: creating a selection object select of the network; associating the socket with the select; associating the abnormal condition of the socket with the select; and associating the reading and writing of the socket with the select.
In a possible embodiment, the creating data related to the socket and linking with the bullet screen server includes: establishing connection with a server by creating int socket (AF _ INET, socket _ STREAM, 0); creating an address family servaddr. Create a port number (servaddr. sin _ port ═ htons (port)); creating a system function int nRet ═ connect (sockfd, (struct sockaddr) & servadr, sizeof (servadr)), and calling the int nRet ═ connect (sockfd, (struct sockaddr) & servadr, sizeof (servadr)) to be linked with the bullet screen server.
In a possible embodiment, the reading the data sent by the bullet screen server received in the socket includes: judging whether the socket is in a Read set Read _ FD _ ISSET or not; if the socket is in the Read _ FD _ ISSET, calling event.OnRead () to inform that data in the socket can be Read; and reading the data sent by the bullet screen server and received in the socket.
In a possible embodiment, the sending the data to be sent to the bullet screen server through the socket includes: judging whether the socket is in a read set Write _ FD _ ISSET or not; if the socket is in the Write _ FD _ ISSET, calling event. And sending the data to be sent in the socket to the bullet screen server.
A second aspect of an embodiment of the present invention provides a mobile terminal, including: the first processing unit is used for creating related data of the socket and linking the related data with the bullet screen server; the system comprises a first determining unit, a second determining unit and a third determining unit, wherein the first determining unit is used for determining a socket breaker of a network interrupt object, and the socket breaker is used for triggering the socket to interrupt a current link; the system comprises a first establishing unit, a selecting unit and a processing unit, wherein the first establishing unit is used for establishing a selection object select of a network, and the select is used for monitoring the state information of the socket; the second creating unit is used for creating an event object event, and the event is used for notifying the state information of the socket; a third creating unit, configured to create a Thread object Thread of the socket and an execution function void __ RunThread (), which executes the Thread; a fourth creating unit, configured to create while loop in the execution function to monitor the state of the socket; the reading unit is used for reading the data received in the socket and sent by the bullet screen server; and the sending unit is used for sending the data to be sent to the bullet screen server through the socket.
A third aspect of the present invention provides an electronic device, comprising a memory and a processor, wherein the processor is configured to implement the steps of the method for linking a bullet screen according to any one of the above first aspects when executing a computer management program stored in the memory.
A fourth aspect of the present application provides a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to perform the method of the above-described aspects.
A fifth aspect of the present application provides a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of the above-described aspects.
Drawings
Fig. 1 is a flowchart of a method for linking bullet screens according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a mobile terminal according to an embodiment of the present invention;
fig. 3 is a schematic diagram of a hardware structure of a possible electronic device according to an embodiment of the present invention;
fig. 4 is a schematic hardware structure diagram of a possible computer-readable storage medium according to an embodiment of the present invention.
Detailed Description
The embodiment of the invention provides a method for linking bullet screens and a mobile terminal, which are used for optimizing the process of linking bullet screens and improving the efficiency of linking bullet screens.
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the 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 terms "first," "second," "third," "fourth," and the like in the description and in the claims of the present application and in the drawings described above, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be practiced otherwise than as specifically illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Example one
Referring to fig. 1, a flowchart of a method for linking bullet screens according to an embodiment of the present invention includes:
101. and creating related data of the socket and linking with the bullet screen server.
And the mobile terminal creates data related to the Socket and is linked with the barrage server. The relevant data includes int sockfd ═ socket (AF _ INET, SOCK _ STREAM,0), address family servaddr.sin _ family ═ ip, port number (servaddr.sin _ port ═ htons (port)), and system function int nRet ═ connection (sockfd, (struct sockaddr) & servaddr, & sizeof (servaddr)).
102. And determining a network interrupt object SocketBreaker.
The mobile terminal determines a network interrupt object, namely, a socket breaker, which is used for triggering socket to interrupt the current link. Specifically, the mobile terminal defines an object function socket pointer, and the object function socket pointer is used for triggering the socket link to terminate the current link.
103. A selection object select for the net is created.
The mobile terminal creates a selection object select of the network, and the select is used for monitoring the state information of the socket. The mobile terminal creates a socket select object (pipe) and monitors the state information of the socket. Specifically, the created socket is associated with the select object, so that the select object monitors the socket. The select specifically includes: exception _ FD _ set (socket) for associating an abnormal condition of the socket; write _ FD _ set (socket) function used to correlate reads and writes of socket. Select may monitor when a socket generates an exception or can send network data, or can read network data, for example, using a function int select _ select. And judging the return value, if the return value selectRet is 0, the set timeout is over time, and the link fails.
104. An event object event is created.
The mobile terminal creates an event object event for notifying the state information of the socket. The mobile terminal creates an event object event for notifying the upper layer of the current socket state information.
The method specifically comprises the following steps: oneror (connectittioutler) function for calling oneror function of Event object Event and parameter set to connectittioutler, indicating a link timeout error; the function event.oneror (ConnectingErr) indicates a link error if the return value selectRet <0, and calls the function event.oneror (ConnectingErr) to notify the upper layer that the current socket is in error. Otherwise, if the link is successful, continuing the subsequent network packet sending and receiving operation; OnConnect () function, OnConnect for calling event object event tells the upper layer that the current link was successful.
105. Creating a Thread object Thread of socket and an execution function void __ RunThread () that executes Thread.
The mobile terminal creates a Thread object Thread of socket and an execution function void __ RunThread () that executes Thread. Firstly, creating a Thread object Thread _, writing a function void __ RunThread () executed by the Thread, then binding the Thread execution function based on the Boost base library and transferring the Thread execution function to an execution function of the Thread, such as Thread (Boost:: bind (& MTcpclient:: __ RunThread, this)), so that the execution logic of the Thread is the function of executing the RunThread function. When all data is initialized, the function Start of the call thread object is moved to Start the execution of the thread function, e.g., thread _ Start ().
106. Creating while loop in the executing function to monitor the state of the socket.
The mobile terminal creates while loop in the execution function to monitor the state of the socket. The related events are processed by creating (writing) while loops to constantly monitor the state of the socket.
The entire logic function of the while loop is in the RunThread function logic, so the independent thread of the socket executes the code logic. And creating a while loop to continuously receive the network data sent by the bullet screen server from the socket and continuously send the network data required to be sent by the client to the bullet screen server from the socket.
First, look at the state of the socket, while (true) { int select ret ═ select ();
if the current unreadable data has no writable data and no exception exists, directly returning to wait for the next state, if (0 ═ select ret) { continue; }
If the current socket generates an exception, an event object event is used for informing the upper layer that an IO read-write error occurs first currently, if (0> selectRet) { event.Oneror (IOErr);
ending the current cycle by return, return; checking whether the socket is abnormal or not next;
judging whether the socket is in an Exception set Exception _ FD _ ISSET or not through a select object, thereby knowing whether the current socket is abnormal or not;
if(select.Exception_FD_ISSET(socket)){event.OnError(IOErr);
and ends the current loop through the loop; }
107. And reading data sent by the bullet screen server received in the socket.
And the mobile terminal reads the data sent by the bullet screen server received in the socket. The mobile terminal judges whether the socket can read the network data of the bullet screen server, and the specific process is as follows: judging whether the socket is in a Read set Read _ FD _ ISSET or not through a select object, so as to know whether the current socket can Read data or not; at this time, the upper layer is informed that the current socket has data to read by calling the OnRead of the event object, so that the network data of the barrage server, if (select.read _ FD _ isset (socket)) { event.onread (); }
108. And sending the data to be sent to the bullet screen server through the socket.
And sending the data to be sent to the bullet screen server through the socket. The mobile terminal judges whether the socket can send the network data to the network data of the bullet screen server, and the specific process is as follows: judging whether the socket is in a read set by a select object so as to know whether the current socket can send data or not by the Write _ FD _ ISSET; at this time, the OnSend of the event object is called to inform the upper layer that the current socket can send network data, so that the data of the client can be sent to the barrage server, if (select.write _ FD _ ISSET); the while loop written in the step can continuously monitor whether the socket is abnormal or not, whether the data can be read or not, and whether the data can be sent to the server or not, so that the program can continuously receive the data of the bullet screen server and send the data to the bullet screen server.
In the embodiment of the invention, the related data of the socket is created and linked with the barrage server; determining a network interrupt object socket breaker, wherein the socket breaker is used for triggering socket to interrupt the current link; creating a selection object select of the network, wherein the select is used for monitoring the state information of the socket; creating an event object event for notifying the state information of the socket; creating a Thread object Thread of socket and an execution function void __ RunThread (), which executes Thread; creating a while loop in an execution function to monitor the state of the socket; reading data sent by a bullet screen server received in a socket; and sending the data to be sent to the bullet screen server through the socket. According to the embodiment of the invention, an asynchronous mode is adopted for bullet screen linking, an independent thread is created for a socket link to execute the whole socket linking process, the bullet screen linking process is optimized, and after the socket receives data, the socket is informed to the upper layer in an event form, so that the upper layer only processes network data without paying attention to the specific implementation of the socket, and the idea of hierarchical design is realized. The efficiency of linking barrage is improved.
Optionally, on the basis of the embodiment corresponding to fig. 1, in an optional embodiment of the method for linking a bullet screen provided in the embodiment of the present invention, the creating a Thread object Thread of the Socket and the executing function void __ RunThread () for executing the Thread include: creating a Thread object Thread of the socket; creating an execution function void __ RunThread (), wherein the execution function void __ RunThread () is used for executing the Thread; and binding a preset basic library Boost with the void __ RunThread (), and transferring the Boost to the void __ RunThread ().
Optionally, on the basis of the embodiment corresponding to fig. 1, in an optional embodiment of the method for linking a bullet screen provided in the embodiment of the present invention, the creating an event object event, where the event is used to notify that the state information of the socket includes: creating an event.OnError (ConnectTimeouther) for the event object event, the event.OnError (ConnectTimeouther) to indicate a link timeout error; creating an event.OnError (ConnectionError) of the event object for calling OnError to notify the Socket of an error; creating an event.OnConnect () of the event object, the event.OnConnect () being used to notify the Socket link success.
Optionally, on the basis of the embodiment corresponding to fig. 1, in an optional embodiment of the method for linking a bullet screen provided in the embodiment of the present invention, the creating a selection object of a network, where the selection is used to monitor the state information of the socket includes: creating a selection object select of the network; associating the socket with the select; associating the abnormal condition of the socket with the select; and associating the reading and writing of the socket with the select.
Optionally, on the basis of the embodiment corresponding to fig. 1, in an optional embodiment of the method for linking a bullet screen provided in the embodiment of the present invention, the creating of the relevant data of the socket and the linking with the bullet screen server include: establishing connection with a server by creating int socket (AF _ INET, socket _ STREAM, 0); creating an address family servaddr. Create a port number (servaddr. sin _ port ═ htons (port)); creating a system function int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr)); and calling the int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) to link with the bullet screen server.
Optionally, on the basis of the embodiment corresponding to fig. 1, in an optional embodiment of the method for linking a bullet screen provided in the embodiment of the present invention, the reading of the data sent by the bullet screen server and received in the Socket includes: judging whether the socket is in a Read set Read _ FD _ ISSET or not; if the socket is in the Read _ FD _ ISSET, calling event.OnRead () to inform that data in the socket can be Read; and reading the data sent by the bullet screen server and received in the socket.
Optionally, on the basis of the embodiment corresponding to fig. 1, in an optional embodiment of the method for linking a bullet screen provided in the embodiment of the present invention, the sending the data to be sent to the bullet screen server through the socket includes: judging whether the socket is in a read set Write _ FD _ ISSET or not; if the socket is in the Write _ FD _ ISSET, calling event. And sending the data to be sent in the socket to the bullet screen server.
Example two
It should be noted that, on the basis of the above embodiments, the present invention may also have other implementation manners, for example, processing data received by a socket and data to be sent based on the design of a message queue at an upper layer of the socket, and the specific embodiments are as follows:
step 1, determining a class of C + + to package a processing process of network data.
The function of this step is to correspond to the upper layer code in step 1, which will receive all event messages of the event. Firstly, in this embodiment, a c + + class is designed to encapsulate processing processes of all network data, and a separate design is performed on errors of a socket in a process of generating data, receiving data, and the whole socket, so that the logic is clearer, a received data event is only responsible for received data, a generated data event is only responsible for sending data, and a socket error event is only responsible for socket error processing. class TcpClient { where a message queue is designed to store all the network data that needs to be sent to the server, while also implementing all event messages. For each piece of network data, a string is formed, so that each piece of message text is stored by using an array of Char; the message queue needs to store network messages frequently and take out the network messages, so that the message queue is more suitable for storing the data structure and the algorithm by using a linked list structure, and the linked list has the functions of quickly inserting data and deleting data. }
And 2, generating a container of the standard template library STL to store the message.
The embodiment uses a container list linked list container of a Standard Template Library (STL) to store network messages, STL: list < char > list message; defining one such object listMessage is the message queue storage process of this embodiment. When a piece of network data needs to be sent, the network data is stored in a message queue, because the message sending embodiment adopts an asynchronous process, packet loss is prevented when the socket cannot send the data, all the network data needing to be sent can be cached through the message queue, and when the socket can send the data, the data is taken out from the message queue for sending. The specific storage messages are as follows: calling a push _ back function of the list class, storing a piece of message data into the linked list and storing the message data into the tail end of the linked list, wherein the push _ back function is the list message (sendbuffer); by calling the front function of the list class, the foremost message data in the list can be taken out from the list, and the message taking-out is as follows: front (); and a list-like pop _ front function needs to be called to remove the message data from the linked list, list message.
And 3, creating an OnRead event of the event, wherein the OnRead indicates that the network data issued by the bullet screen server is read.
The event functions that receive the underlying socket in step 1 include an OnError event, an OnRead event, and an OnSend event. void OnRead () { for the OnRead event, when the underlying code sending socket can read the network data, the underlying code is informed to read the network data. In this embodiment, a system function recv may be called to read network data in the socket, and ssize _ t ret ═ recv (socket, (char) buf, len, 0); buf is used for storing read data, and len is the read length. When the function call is completed, the network data is stored in the buf, so that the receiving of one piece of network data is completed, and the received data is stored in the message queue; defining a message queue mq; the mq is a message queue object, and this embodiment supports a plurality of threads to store received messages into the message queue at the same time, and also supports a plurality of threads to fetch messages from the message queue at the same time. So this embodiment defines a Mutex write _ Mutex; the mutex object write _ mutex; then define a lock to lock the mutex object, scopedLock Lock lock (write _ mutex _); then, calling the message queue object to store the received network data, mq.write (buf, len); indicating that a message is stored in the message queue. This embodiment puts all received messages into the message queue mq. }
And step 4, creating an OnSend event of the event, wherein the OnSend indicates that data can be sent to the bullet screen server.
For the OnSend event, when the bottom layer code finds that the current socket can send network data, the message is taken out from the message queue to be sent; one message queue is used for buffering all messages sent to the server, so that the application layer can send data in a multi-thread mode. Defining a message queue mq 2; where mq2 is the object of the message queue, and the sending message is continuously taken out from the message queue for sending. To support multithreading, the embodiment defines a Mutex read _ Mutex; the mutually exclusive object read _ mutex; then define a lock to lock the mutual exclusion object, scope Lock (read _ mutex _); then calling the message queue object to take out the network data to be sent for sending, mq2.read (buf, len); thereby obtaining data buf needed to be sent, and then sending send (socket, buf, len) the message by using a system function; }
And 5, creating an OnError event of the event, wherein the OnError indicates that the socket encounters an error in the whole link or data receiving and sending.
void oneror (int nStatus) { for oneror event, when the bottom layer code finds that the current socket link has an error, the bottom layer code informs the application layer, the socket has the error, needs to be processed, and gives a specific status code. After receiving the status codes, for better design, the status codes need to be distinguished, some status codes do not need to be reconnected, some status codes need to be reconnected, and the specific details are not limited herein. }}
The embodiment is based on a layered design idea, and the upper layer decouples the network transceiving of the bottom layer, so that a better layered design is provided, the coding is optimized, and the logic processing is clearer. In this embodiment, a message processing queue of an upper socket is designed to process received data of the socket and data to be sent, so that the processing efficiency of the linked bullet screen is improved.
EXAMPLE III
It should be noted that, on the basis of the above embodiments, the present invention may also have other implementation manners, for example, a link scheme is designed based on socket status codes, and whether reconnection is performed is designed, and specific embodiments are as follows:
step 1, generating a mapping table for storing the state codes.
Firstly, there are many kinds of status codes, and when a socket has an error, the currently generated status code needs to be taken to inquire whether reconnection is needed. The performance of the query needs to be considered once it is involved. The present embodiment stores the status code based on the map container of the standard template library STL container. When in query, the searching speed is very fast based on the map container, and map < int, pool > mapStatus; this example defines a map < int, pool > type of object mapStatus. Wherein. The first parameter int is a key value of the map container and is used for storing the state code of the socket, and the second parameter pool is used for storing whether the current state code needs to be reconnected. All state codes are then known, and need to be marked and stored in the map container object. The status code of the status codes indicating an error may also be referred to as an error code.
And 2, determining all possible states and state codes in the whole link process of the socket, wherein the state codes correspond to the possible states one to one.
All status codes include all the conditions that may occur during the entire use of the entire socket as follows: kInitErr, which indicates the initialization error code. ksockthreadstart, which means socket initialization thread. ksockthreadstarterr, which indicates the socket initialization thread error code. ktcponnectiperr, which indicates that an error code is generated when socket links ip. ktcponnecttimeouterr, indicating that the socket has timed out. ktcpieoerr, indicating that the socket sent data produced an io error code. kTcpDisConnectedbyRemote, indicating that the socket is closed by the server. kTcpDisConnected, indicating that the socket link is broken.
This embodiment uses integers for all of the above status codes. And all error codes cannot have the same value.
The present embodiment is designed using a technique enumerated variable type of the C + + language so that the compiler will help check that the values of all state codes are non-repeating.
enum SocketStatus{kInitErr=1,kSocketThreadStart,
kSocketThreadStartErr,kTcpConnectIpErr,kTcpConnectTimeoutErr,
kTcpIOErr,kTcpDisConnectedbyRemote,kTcpDisConnected,
};
This embodiment defines an enumeration variable enum SocketStatus; all state codes are included in the enumerated variables. And the value of the first state code is assigned to be 1, then other subsequent state codes automatically add 1 on the basis of the first state code, so that the values of all the state codes cannot be repeated. For example, the value of ksockthreadstart is 2, and the value of ksockthreadstarterr is 3, which will not be described herein again.
And 3, storing the state code into a mapping table.
For all the status codes, some are error codes generated during linking, some are error codes generated during data transmission, and some are normal closed socket links. The reconnection needs to be treated differently when the reconnection is performed, and the reconnection needs to be performed immediately after some errors are sent, so that a user can see the bullet screen immediately to prevent disconnection of bullet screen links; and some clients are normally closed, or the server normally closes the clients without reconnection. The status code assignment is then required for the mapStatus container object. Specific codes are explained below.
mapStatus [ kInitErr ] ═ true; this line code indicates that the key value of kInitErr is stored in the mapStatus container and whether reconnect is set to true, indicating that this state code needs to be reconnected.
mapStatus [ ksockrethreadstart ] ═ false; this line code indicates that storing the key value kSocketThreadStart into the mapStatus container and whether reconnect is set to false, since only initialization is done, reconnect is not needed.
mapStatus [ ksockrethreadstarterr ] ═ true; this line code indicates that storing the key value kSocketThreadStartErr into the mapStatus container and whether reconnect is set to true, reconnect is needed because it is a create thread error.
mapStatus [ ktcpnnectiperr ] ═ true; this line code indicates that storing the key value ktcponnectiperr in the mapStatus container and whether reconnect is set to true, and reconnect is required because an error is generated when connecting IP.
mapStatus [ ktcpnnecttimeouterr ] ═ true; this line code indicates that storing the key value ktcponnecttimeouterr in the mapStatus container and whether reconnect is set to true, reconnect is required due to timeout error.
mapStatus [ ktcpieorr ] ═ true; this line code indicates that storing the key value kTcpIOErr in the mapStatus container and whether reconnect is set to true, and reconnect is required because of data read and write errors.
mapStatus [ kTcpDisConnectedbyRemote ] ═ false; this line code indicates that storing a key value of ktcpndisconnectedbyremote into the mapStatus container and whether reconnect is set to false, since it is the server that closes the link, reconnect is not required.
mapStatus [ ktcpdconnected ] ═ true; this line code indicates that storing the key value ktcpndisconnected into the mapStatus container and whether reconnect is set to true, a reconnect is required because the link is not stably disconnected. Up to this point, the values of all the status codes have been stored in the mapStatus container, and whether to reconnect each status code is set.
And 4, judging whether reconnection inquiry is needed or not according to the state code.
When the socket sends an error, the query interface queries whether the reconnected interface is available according to the error code, if the reconnected interface needs to be reconnected, the reconnection is automatically carried out, otherwise, the link is disconnected. If other new status codes need to be added, a status code type can be added into the enum SocketStatus first, and then the mapStatus container is assigned. Next, in order to design better packing, the present embodiment designs an interface to inquire whether a status code needs to be reconnected. The specific process is as follows:
bool GetRetryFlag(int nStauts)
{
wherein, the interface return value is a bol variable, a true value indicates reconnection, and a false value indicates non-reconnection; the interface name is GetRetryFlag; wherein, only one parameter int nStauts represents the state code of the query;
then, the query interface find interface of the map container is needed to be used:
map<int,bool>::iterator itr;
firstly, defining an iterator of a map container;
itr=mapStatus.find(nStauts);
then calls its find interface to query the current state code and the query result is stored in itr iterator, where the value of the iterator is the result value.
retrun(*itr).value;
Then the value of the iterator is taken as the return result.
}
With the state code query interface, whether the current state needs to be reconnected or not can be obtained through query, so that basic technical support is provided for an application layer, and whether the reconnection is carried out or not is carried out by the application layer according to a query result.
According to the embodiment of the invention, the scheme of linking the barrage is designed based on the socket state code, and when the network of the mobile terminal is unstable and the barrage is disconnected, the mobile terminal can also use the automatic reconnection technology to reconnect the barrage, so that the processing efficiency of the linked barrage is improved, and a user can not sense the barrage, and further the user experience is improved.
Example four
It should be noted that, on the basis of the above embodiments, the present invention may also have other implementation manners, for example, a link scheme is designed based on an error code issued by a server, and whether to perform reconnection is designed, where specific embodiments are as follows:
at barrage link in-process, the barrage server can check the identity of the client that the barrage is linked to, also can inspect the protocol that links simultaneously, include: detecting the protocol type and checking the protocol field. Meanwhile, whether each field is legal or not, whether illegal characters exist or not, whether an error protocol exists or not and the like are judged. Meanwhile, the client may send some abnormal data and the like in the linking process, so that the bullet screen server returns different error codes to different situations of the client. For example, when the client logs in the bullet screen server, the token field used by the client is not the token logged in by the client account password, and at this time, the bullet screen server returns a specific error code indicating that the link token is incorrect.
Specifically, when watching live broadcast, the room number given by the linked barrage server does not exist in the live broadcast platform, so the barrage server also returns a specific error code at this time; when the client exits the room, the link of the bullet screen server is disconnected, and the bullet screen server returns a specific error code; similarly, if the network of the current user is unstable, the client does not send a specific mental state data packet to the server for a long time, and the server judges that the network of the client is unstable, also considers that the client loses the link, and then returns a specific error code; when the client and the server perform network data transmission, if the data sent to the server by the client is incorrect at a certain probability, the server also sends a specific error code to the client; it is also possible that, in the case where the user has multiple devices with one account, the same account logs in the same live broadcast room by using multiple different devices at the same time, and the server returns a specified error code. Therefore, different error codes need special treatment, and only some error codes need to be reconnected. The specific implementation is as follows:
step 1, generating an error code message subscriber class ErrorMessageObserver.
The subscriber, class error MessageObserver, who must implement all the abstract interface functions of the MessageObserver, who generates a server error message, first defines a static container object type,
public MessageObserver{public:const std::set<std::string>&GetObserverMessageType(){static std::set<std::string>types;
if the types store all the messages needing to be subscribed, returning directly, otherwise, storing no subscribed message, if (! types. }
types.insert(error_TYPE);
A message type may be inserted into a container object by calling an insert function. In this embodiment, an error _ TYPE is subscribed if the error message is received. }
And step 2, determining an interface of an error code message subscriber.
Another abstract interface OnRecvPackMsg is implemented. The message subscription and distribution management module calls the interface to distribute the error message to the subscriber after receiving the error message, where the error message is an error message subscriber, and the server receives all the error messages sent by the server, and the server is a corresponding bullet screen message.
The message needs to be parsed first, and the error code of the message is also obtained from the error message. For example, when receiving a message that one account logs in multiple devices and enters the same live broadcast room, the message that the server receives is as follows: type @ error/code @ 500; where type @ error indicates that the message type of this message is error. Where code @ 50 indicates that the error code of this message is 500.
And 3, analyzing the message.
After receiving the message, the message needs to be parsed. Firstly, a message parser needs to be created, pDecoder message decoder ═ pDecoder ═ new message decoder (); then calling a Parse interface of a resolver to resolve the message, wherein pDecoder- > Parse (pservvermessage); after the parsing is completed, a value of a code field of the error code needs to be obtained, so as to obtain a value of an error code, where int errorcode is pDecoder- > GetItem ("code"); and calling a GetItem interface of the error code generator to obtain the value of the error code of the code field, and assigning the value to an error variable. After the error code is obtained, the error code is needed to specifically realize the corresponding logic function: first, the embodiment classifies the errorcode, some require reconnection, some do not require reconnection, and some require separate processing. The error code that needs to be reconnected is put into an enumeration variable, enum RetryCode { KDisconnect ═ 50, which indicates that the error code is 50, and the link is lost due to network instability; kDataError ═ 60, indicating that the error code is 60, due to its data field loss; the kIOError is 70, which indicates that the error code is 70 due to data error during transmission. }; then reconnection is required for such error codes.
And 4, generating a map container of the error codes and correlating the error codes.
In the same embodiment, a map container is designed to store the reconnected error code, and the reconnected error code is queried after the server sends an error message. The same defines that another map container stores error codes that do not need to be reconnected.
map<int,bool>mapRetry;
This embodiment defines a maprotation container object.
mapRetry[KDisconnect]=true;mapRetry[kDataError]=true;mapRetry[kIOError]=true;
For non-reconnect operations the following are:
enum NotRetryCode{
the kTick is 500, which indicates that the error code is 500, and since the same account number logs in a plurality of devices and logs in the same live broadcast room at the same time, the barrage server kicks off a client. At this point, reconnection is not possible.
kClientDisconnect is 501, which means that the error code is 501, which means that the client actively closes the current link, and thus, no reconnection is required.
}
The same defines that another map container stores error codes that do not need to be reconnected.
map<int,bool>mapNotRetry;
mapNotRetry[kTick]=false;
mapNotRetry[kClientDisconnect]=false。
And 5, determining an error code of the specific message to reconnect the logic.
After receiving an error message, firstly, whether reconnection is needed is inquired according to the error code, and then whether reconnection is not needed is inquired, wherein the specific process is as follows:
map<int,bool>::iterator itr;
an iterator is first defined.
Fine (error) itr ═ maproterty; the query is then made using the error code obtained from the error message.
if (itr ═ maprotery. end () { indicates that no duplicate error code was found; then, error codes which do not need to be reconnected need to be searched;
itr=mapNotRetry.find(errorcode);if(itr==mapNotRetry.end()){
if no description is found and is not in the error codes which do not need to be reconnected, the error codes need to be further processed;
if (error code 800) { where the error code 800 indicates a room number error, the client can obtain the room information from the global information center.
int nRoomId=Datacenter()::instance()->getRoomid();
In this embodiment, the information related to the live broadcast room is stored in the data center Datacenter, and when the linked bullet screen server finds that the room number is wrong, the room number may be obtained from the information center again for reconnection.
Reconnecting again after all the obtained data are obtained;
int nRet=connect(sockfd,(struct sockaddr*)&servaddr,sizeof(servaddr));
continuing to use the code of step 1 for network linking;
else if (error code 900) { where the error code 900 indicates that the token of the current link is invalid, and at this time, the correct procedure is to request the token again and then reconnect, then the client uses the HTTP request to obtain a new token, and after obtaining the new token, the bullet screen link is performed.
token=http.get()
In this embodiment, token data is obtained through a get function of http, and after the token is obtained, reconnection is performed again.
}
}else{
The description is found, and the description does not need to be reconnected; in this embodiment, the Break function of the previous pipe object is called to disconnect the current network link;
pipe.Break();
}
}else{
if the instruction is found, reconnection is carried out;
int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr)); continuing to use the code of step 1 for network linking.
}
According to the embodiment of the invention, based on some error codes of the mobile terminal in the process of finding the linked barrage, the mobile terminal can also use the automatic reconnection technology to reconnect the barrage, so that the processing efficiency of linking the barrage is improved, and a user can not feel the barrage, thereby improving the user experience.
EXAMPLE five
It should be noted that, on the basis of the above embodiments, the present invention may also have other implementation manners, for example, a design link scheme for network data distribution based on message types, and the specific embodiments are as follows:
step 1, determining a message subscriber abstract interface MessageObserver based on C + + language.
The embodiment develops a design of an interface based on the C + + language, designs a uniform interface and abstract class for a message subscriber, the message subscriber must implement all interfaces of the abstract class, and the message management class needs to manage all message subscribers. First, an abstract interface class MessageObserver, class MessageObserver { definition of public function: public, MessageObserver () { }, which does not need to implement what function is a null function;
defining a destructor of the virtual-; defining an abstract interface function GetObservermessageType to represent that all message types subscribed by a subscriber are acquired, and adding 0 in a code to represent that the code is an abstract interface;
wherein the return type is a set container of the stl container, the message types are all string types, the virtual const std is set < std:: string > & GetObservermessageType () > 0; set < std:: string > indicates that multiple different message types can be stored and that the message types cannot be the same. Then another abstract interface OnRecvPackMsg is defined, which indicates that the underlying network receives the network data to push to the subscriber.
This function must also be a virtual function and must be added to 0 to represent an abstract interface, where the parameter conststd:: string _ cmdtype represents the type of message currently pushed, where the parameter constchar _ pservermessage represents the entire message content, and the parameter virtual void OnRecvPackMsg (conststd:: string _ cmdtype, constchar _ pservermessage): 0.
And 2, determining the object copy prevention function of the abstract interface.
Next, since this subscriber embodiment does not allow it to make copies between objects, the copy constructor needs to be defined as a function of the null implementation and needs to be put into a private function. Defining an assignment copy function as a private null-implementation function, wherein the private is a void operator & (const MessageObserver &); defining a copy constructor function as a private null-implementation function, MessageObserver (const MessageObserver &); by this time, the subscriber's interface class has completed all its definitions. All subsequent concrete subscribers then define their own implementation based on the abstract class MessageObserver.
And step 3, generating an message subscriber management class Observermanager.
Firstly, defining a message manager class observer manager; in the embodiment, subscribers are designed based on message types, each subscriber can subscribe the message type in which the subscriber is interested, and there may be multiple subscribers for one message type. It requires member variables to store all message subscribers and simultaneous message subscribers subscribe to multiple message types. The present embodiment manages message subscribers using a multimap container of STL because each message subscriber may subscribe to multiple messages, and because messages are frequent, the present embodiment also needs to be able to quickly find all subscribers to a message, so the present embodiment manages message subscribers and queries message subscribers using multimap. An object map _ push _ observer of multimap is created to store the subscriber, where the key value of multimap is std:: string represents the type of message, the vlaue value of multimap is the message observer represents the object pointer of subscriber, std:: multimap < std:: string, message observer > map _ push _ observer.
And 4, providing the subscriber to the writing interface through the interface of the subscriber management class Observermanager to subscribe the interested messages.
The interface provides all subscribers registered in the message management object to all subscribers, and must be the subscribers written before in this embodiment, based on the abstract class MessageObserver, void SetMessageTypeObserver (messageObserver) _ taskObserver
Then all message types that the subscriber needs to subscribe to need to be acquired. The subscriber provides a uniform abstract interface GetObserverMessageType for obtaining;
const std::set<std::string>&_cmdtypes=_taskObserver->
the returned value _ cmdtype stores all message types needing subscription, GetObservMessageType (); then, traversing the return value to acquire all message types; defining an iterator object std set < std:string >: iterator itr; initialize iterator itr ═ _ cmdtype. Then writing a for loop to traverse to obtain each message type, and judging whether the iterator is equal to _ cmdtype.end (), if the loop is ended; for (; itr! cmdtype. end (); get the message type strType, + + itr) { StringStrType ═ itr from the iterator; next, calling an insert interface of the multimap container to insert a subscriber into the container; map _ push _ observer.insert (std:: pair < std:: string, MessageObserver > (strType, _ taskObserver)); wherein strType represents the type of the subscribed message, and taskObserver represents the subscriber.
}
This interface then completes the registration of the subscriber.
And 5, analyzing the message of the message subscriber management class and distributing the analyzed message to all subscribers.
In step 2, after receiving the network data of the server, the mobile terminal stores the network data in the message queue mq. For each message in the queue we need to parse the message and then invoke the message distribution management class to distribute the message to the corresponding subscribers. Firstly, a message parser pDecoder needs to be created, namely, new message decoder pDecoder (); then reading a message from the queue for analysis;
then the message is stored in buf, mq.read (buf, len); then, a message parser is called to parse the message buf, and the type, pDecoder- > Parse (buf) of the message is obtained from the message parser; thereby obtaining the message type of cmdtype, std:, string cmdtype ═ pDecoder- > GetItem ("type"); the message then needs to be distributed. The embodiment compiles an interface to distribute the message to the corresponding subscribers; a void dispatch message (char × message, string cmdtype) { first obtaining the number n of subscribers to the message through the count function of the multimap container, int n being map _ push _ object.count (cmdtype); firstly, acquiring the number n of subscribers of the message through a count function of a multimap container, and then defining an iterator std, wherein multimap < std:: string, MessageObserver:: itrator itr; the find function is then invoked to find the corresponding subscriber from the iterator.
After the search is carried out, the search result is stored in the iterator itr, and then a for loop is written to be distributed to each subscriber one by one, wherein itr is map _ push _ observer.
for(int i=0;i<n;i++){
Firstly, judging whether a subscriber exists or not;
if(it!=map_push_observer_.end()&&it->second)
{ then calling a corresponding message receiving interface OnRecvPackMsg for each subscriber;
when a message subscriber subscribes a message with the message type of cmdtype, the OnRecvPackMsg is triggered, and the message is distributed to the subscriber; so that the subscriber can further process the message, it- > second- > OnRecvPackMsg (cmdtype, pMessage); for example, a gift message subscriber, the currently received gift message may be presented on the user interface; if the user is a bullet screen message subscriber, the currently received bullet screen message content can be displayed on the user interface.
}
++it;
}
And finishing the design of the subscriber of the message, the management of the subscriber and the distribution of the subscribed message.
And 6, determining the subscriber of each message.
The present embodiment determines the subscribers to each barrage message.
class DanmuMessageObserver:public MessageObserver{
It must implement all abstract interface functions, public, of the MessageObserver;
constststd:: set < std:: string > & GetObservMessageType () { first defining a static container object type;
static std: set < std: string > types; if the types stores all the messages needing to be subscribed, directly returning;
if(!types.empty()){
return types;
else, no subscribed message is stored.
types.insert(danmu_TYPE);
A message type may be inserted into a container object by calling an insert function. In this embodiment, the bullet screen message subscribes to danmu _ TYPE;
implementing another abstract interface OnRecvPackMsg.
void OnRecvPackMsg(const std::string&_cmdtype,const char*pservermessage){
When the message subscription and distribution management module receives the bullet screen message, the interface is called to distribute the bullet screen message to the subscriber. In this embodiment, the bullet screen message subscriber will receive the bullet screen message; after receiving the barrage message, the barrage message can be placed in a display area to display the barrage content, and the pservvermessage is the corresponding barrage message.
In this embodiment, a bullet screen display interface of the UI display layer is called to display a bullet screen.
DanmuUIShow pUIShow=new DanmuUIShow();
pUIShow- > showDanmu (pservvermessage); and then calls its showDanmu to display the bullet screen in the bullet screen display area.
}
And finishing the realization of all interfaces of the bullet screen message subscriber and displaying bullet screen contents.
The embodiment of the invention manages all message subscribers through the classification of the message types and the message management module, and distributes the messages to the subscribers after receiving the messages. The message manager can manage without knowing the subscriber, so that the processing efficiency of the linked barrage is improved, and the user can not perceive the barrage, thereby improving the user experience.
EXAMPLE six
It should be noted that, on the basis of the above embodiments, the present invention may also have other implementation manners, for example, a link scheme is designed based on a network environment, and the specific embodiments are as follows:
with the popularization of internet protocol 6 (IPV 6), for a mobile terminal, a network of internet protocol 4 (IPV4) or a network of internet protocol 6 (IPV 6) may be used, and if a barrage server itself only supports a network of IPV4, it is necessary to convert the address of IPV6 of the client of the mobile terminal into the address of IPV4, and link the server through the address of IPV 4. When it is necessary to ensure that the linked barrage is supported, the mobile terminal may link a barrage server of internet protocol 4 (IPV4) in the environment of IPV 6. When the user selects an available Internet Protocol (IP) based on multiple Internet Protocols (IPs) or domain names, how to make the user view the bullet screen as quickly as possible is a primary problem. The invention provides a solution, which comprises the following specific steps:
step 1, determining the network type of the bullet screen server.
When a client (installed on a mobile terminal) starts to link a bullet screen server, since the IP of the server is IPV4, whether IPV4 or IPV6 is local, the client needs to convert to the network address of IPV4 for linking, and then the client needs to determine whether IPV4 or IPV6 is currently the network, and if IPV6 is the network, the client also needs to convert to IPV 4.
And 2, judging whether the current network environment is IPV4 or IPV 6.
The embodiment needs to determine whether the current network is the network environment of IPV6, if so, it is IPV6, and if not, it is IPV 4. This embodiment unlinks by defining a network address for the IPV6 if successful, which currently supports IPV6 networks. For the IPV4 embodiment, the IP address of the server is selected as 2000::0, and for the IPV6 embodiment, the IP address of the server is selected as 2000:: 0. The concrete implementation is as follows:
defining an address information variable struct socket addr _ in addr of a socket; addr, sin _ len, addr, sin _ family, AF _ INET6, where this time the IPV6 is used and then assigned, where the port number uses 80 ports, then IP uses 2000:, is the address of an IPV6, addr, sin _ port is 80, addr, sin _ addr, s _ addr is {//2000 {// 0:, 0x20,0,0,0,0,0,0,0,0,0,0 }.
Next, a socket is created, and a User Datagram Protocol (UDP) protocol is used, because this embodiment only tests whether the IP of the current server can be connected, this embodiment uses UDP, because the speed of UDP is relatively fast, and int is socket (pf, SOCK _ DGRAM, IPPROTO _ UDP).
Then, calling a system function connect to link, where int ret is connect (s, addr, addrlen); if the return value ret is 0, the link is successful, otherwise the link fails. If the link successfully indicates that the IPV6 is currently supported, if the link successfully indicates that the current IPV6 network environment is currently supported, otherwise, the current IPV4 network environment is currently supported, and if the current IPV4 network environment is currently supported, the link of the bullet screen server can be directly performed.
And 3, converting the network address of the IPV6 into the network address of the IPV 4.
If the address is IPV6, address translation is also needed, and the address of IPV6 is translated into the address of IPV4 through a system function socket _ inet _ ntop. The concrete implementation is as follows: firstly, defining a variable of an IPV4 for storing a converted IPV4 address, char IPV4[100] ═ 0 }; calling a system function socket _ inet _ ntop for conversion, wherein the parameter addr.sin6_ family represents an IPV6 address protocol, and the parameter addr.sin6_ addr is the address of an input IPV 6; the parameter IPV4 stores the converted result, i.e., socket _ inet _ ntop (addr. sin6_ family, & (addr. sin6_ addr), IPV4, sizeof (IPV 4)). The mobile terminal determines whether the current network environment is IPV4 or IPV6, and if IPV6 needs to convert the address because the server uses the address of IPV4, so that the mobile terminal according to this embodiment may be linked to the bullet screen server of IPV4 in the network environment of IPV 6.
And 4, connecting the bullet screen server based on the converted IPV4 address.
After converting the network address of the IPV6 into the network address of the IPV4, the mobile terminal may directly connect to the barrage server. A connection is established with the server, int socket fd ═ socket (AF _ INET, socket _ STREAM, 0). Sin _ family ip; port number (host endian to network endian), servaddr.sin _ port ═ htons (port); calling a system function connect to start to connect to the barrage server, and connecting to the barrage server directly through the connect, where int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servadr)).
According to the embodiment of the invention, the network address of the IPV6 is converted into the network address of the IPV4, so that the mobile terminal can be linked with the barrage server only supporting the IPV4 under the environment of the IPV6, and the processing efficiency of linking the barrage is improved.
EXAMPLE seven
It should be noted that, on the basis of the above embodiments, the present invention may also have other implementation manners, for example, monitoring network switching of the current network environment, and performing reconnection design link scheme based on the monitoring result, and the specific embodiments are as follows:
since mobile terminal devices are usually mobile and are very different from PC devices, the process may move with the user's location, and network handover may occur as the process moves. For example, when WIFI is used at home, the network may be switched to 4G after going out, and a network with a strong signal may be switched to a network with a weak signal. Specifically, when the 4G network is switched to the WIFI network, it is necessary to monitor that the current network is changed, so as to disconnect the current network link, reuse a new network for linking, and link the bullet screen server in the new network more quickly. When the network is switched to the non-signal network or the weak-signal network from the network or the strong-signal network, in order to save the electric quantity, the overtime reconnection of the network bottom layer is needed to be used, and the overtime is set for a longer time to reconnect the bottom layer network, so that the electric quantity is saved. In this embodiment, a method for designing a linked bullet screen according to an Android system includes the following specific steps:
step 1, defining a network link type to store the current network type and generating the state code of the network type.
In this embodiment, a network link type is defined to store the current network type, and an enumeration variable is determined to store the network type, which is defined as a NetStatus enumeration type.
enum NetStatus { kNONET ═ 1, kffi, k4G }; where kNONET is defined to mean that there is no network currently and the value is 1; defining kWIFI to represent that the current network is WIFI, and automatically assigning a value of 2; if k4G is defined to indicate that the current network is a 4G network, the value is automatically assigned to 3, and the network state NetStatus currstatus is defined.
And 2, generating a monitoring class of the network state in the Android system.
For the Android system, monitoring the current network change requires writing a subclass to inherit to the broadcastrecherver class of the system and monitoring the network event therein. In this embodiment, a NetworkChange class is defined, which is inherited to the broadcastreever of the system, i.e., a subclass NetworkChange class is generated, which is inherited to the broadcastreever class of the system.
public class NetworkChange extends BroadcastReceiver{
Then reloading its interface to receive network changes;
@Override
public void onReceive(Context context,Intent intent){
judging whether a network is connected currently;
if(ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())){
then judging the current network state through the ConnectiontManager attribute;
defining a NetworkInfo object info and a NetworkInfo;
then the current network information is obtained. Specifically, the current NETWORK information may be obtained through a system function getparamebleextra, and the incoming parameter is connectivity manager.
info=intent.getParcelableExtra(
ConnectivityManager.EXTRA_NETWORK_INFO);
After the info information is obtained, whether WIFI, 4G or no network exists is judged;
if(info.getType()==ConnectivityManager.TYPE_WIFI){
the current network type can be obtained through an interface getType of info;
type _ WIFI, indicating that the current link is WIFI, and setting the network status type as a WIFI network; curStatus is kWIFI;
}else if(info.getType()==ConnectivityManager.TYPE_MOBILE){
if the current link is not WIFI, the type of the current link is judged to be connectivitymanager, TYPE _ MOBILE, and if the type of the current link is not WIFI, the current link is indicated to be a 4G network of the MOBILE phone.
curStatus=k4G;
}else{
curStatus=kNONET;
I.e. indicating that no network is currently available, is in a network disconnected state.
}
}
}
}
And 3, instantiating the monitoring class and registering the system.
To monitor the current network also calls system functions to register.
Firstly, an IntentFilter () is required to be created; add interception of the network by calling addAction function of intetfilter, filter. Wherein the incoming parameter is connectivitymanager. Then instantiating an object of a NetworkChange class, wherein the NetworkChange network is new NetworkChange (); next, calling a register receiver function of the system to register network monitoring, register receiver (net, filter); thereby realizing the monitoring of the network.
And 4, monitoring the state code of the network type through a register receiver function, and linking the bullet screen server according to the change condition of the state code.
Some adjustments to the bullet screen links are then needed depending on current network changes. If the current network state is obtained by the monitoring network, the current network state is compared with the previous network state, and if the network state is not changed, the current barrage link is not operated. If the network state changes, the network needs to be changed according to the current state change. Defining a variable NetStatus prevStatus ═ kNONET at the start of a program; and initializes its value to a state of no network. When the network state is checked once, the current network is assigned to it to store the previous network state. prevStatus is curStatus. When the network is switched, whether the bullet screen link is operated or not is judged according to the previous network and the current network state.
if(prevStatus==curStatus){
If the current network state is the same as the previous network state, the network is not changed, and the bullet screen link is not changed.
Else { if (kvstatus) } kNONET } { if there is no network before, there is a network now, it needs to perform barrage linking.
Continuing to use the code of step 1 for network link, int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr));
}else if(prevStatus==kWIFI){
if the existing state is WIFI state before, the existing network state changes, and if the existing state is 4G network, the existing bullet screen link needs to be disconnected as soon as possible, and the new network is used for re-linking. The present embodiment calls the Break function of the previous pipe object to disconnect the current network link.
Break (), after disconnecting the network;
the reconnection operation is needed again, and the network link is continued to be performed by using the code in step 1, and int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr));
}else if(prevStatus==k4G){
if the network belongs to the 4g network before and is WIFI at present, the network is required to be disconnected immediately, and a new network is required to be linked again. The present embodiment calls the Break function of the previous pipe object to disconnect the current network link.
Break (), after disconnecting the network; the reconnection operation is needed again, and the network link is continued to be performed by using the code in step 1, and int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr));
}
}
}
according to the embodiment of the invention, when the network or the strong signal network is switched to the no-signal network or the weak signal network, the overtime reconnection of the network bottom layer is used, and the overtime is set to be longer, so that the bottom layer network is reconnected, the electric quantity is saved, and the processing efficiency of the link bullet screen is improved.
Example eight
It should be noted that, on the basis of the above embodiments, the present invention may also have other implementation manners, for example, link schemes are designed based on fast switching or selecting IP that can be linked, and specific embodiments are as follows:
in order to ensure that a client on a mobile terminal can link a bullet screen server (server), the server usually provides an IP list of a plurality of servers for the client to select, and the client can arbitrarily select the IP of one server as the IP of the server itself. The existing rule is to select an IP from an IP list for linking, but when an IP server fails or the network line fails, the client needs to switch or select the IP that can be linked quickly. And under the condition that the server still has the domain name, the domain name needs to be analyzed to obtain more IP, and more proper IP needs to be selected on the link for linking so as to improve the whole link speed.
Step 1, defining IP and port data structure.
Assume the existing IP list is as follows: ip1:119.23.45.6port:4002ip2:118.34.32.7port:4002ip3:120.45.33.1port:4008ip4:121.55.23.8port:2009ip5:130.55.23.8port: 4009; in this embodiment, a structure of an ip and a port is defined, and a current ipportitem { string ip; int port; the structure contains ip data and port data, and each ip and port can be stored by the ipportitem.
And step 2, determining the domain name of the bullet screen server.
In order to improve the success rate of user connection while providing the barrage server IP, the speed of linking is already high, and the domain name has a function of performing a preferred nearest network according to the current geographical location of the user. Meanwhile, in order to prevent unlinking, a domain name danmu.dy.com client is provided, and the connectable ip needs to be quickly selected from the ip, so that the subsequent connection to the barrage server can be quickly realized.
And 3, selecting balanced IP supporting the barrage server load.
In order to ensure that the IP clients given by the server can carry out certain randomness, all the clients can not select the same IP to cause the crash of the server due to overhigh load. There is also some possibility that some ports of the client are blocked and cannot be linked to the server. Thus randomly shuffling the links that need to be picked for different ports to try.
And 4, resolving the IP address according to the domain name of the bullet screen server.
Firstly, the client needs to resolve the domain name to obtain more IP addresses. Then the IP of domain name resolution and the IP issued by the server are randomly disturbed, and the system provides a getaddrinfo function to convert the domain name into an IP address. The present embodiment may call a system function to implement domain name conversion. The result of the domain name conversion function is stored in struct addrinfo structure, so the corresponding structure needs to be defined. struct addrinfo hits, single, result; this embodiment defines 3 such structural variables. Variables need to be cleared, memset (& hits, 0, sizeof (hits)); ai _ family ═ PF _ INET; ai _ SOCK type ═ SOCK _ STREAM; then, assigning the hits information, in this embodiment, acquiring the ip corresponding to the domain name, so that the SOCK type is assigned as SOCK _ STREAM. Next, a system function getaddrinfo is called to resolve the domain name. getaddrinfo (host _ name, NULL, & hits, & result); the host _ name, which is a parameter to be transmitted, is a domain name, and after the call of the danmu.dy.com function in the embodiment is completed, the result is stored in the hits and the result; and one domain name or a plurality of ip are analyzed, then the domain name is stored in the result in a form of a linked list. A for loop is then written to traverse the parsed ip list. for (single- > ai _ next) { result is stored in result, and the next result is in the ai _ next structure, which is obtained by traversal in this embodiment. The const char ip is single- > ai _ addr.ip; in each linked list structure, data is stored in the ip attribute.
And 5, generating a container object ipportitem item to store the acquired multiple IPs.
In this embodiment, a vector < ipportitem > vecip is designed; this embodiment defines a container object to store the acquired IP, ipsortimem item.
Firstly, creating an item, and then assigning the item, wherein ip is ip; port ═ port; push _ back (item); the ip is stored in the container by calling the push _ back function of the container, and the above ip and port also need to be stored. ipportitemtem 1; item1.ip 119.23.45.6; item1.port 4002; push _ back (item 1); ipportitemtem 2; ip 118.34.32.7; item2.port 4002; push _ back (item 2); ipportitemtem 3; ip 120.45.33.1; port 4008; push _ back (item 3); ipportitemtem 4; ip 121.55.23.8; port 2009, item4. port; push _ back (item 4); ipportitemtem 5; item5.ip 121.55.23.8; item5.port 4009; push _ back (item 5); until this all ips and ports have been stored in the vecip container.
And 6, randomly disordering the obtained multiple IPs.
The data in vecip needs to be shuffled randomly next. A corresponding interface random _ shuffle is provided for the STL container to randomly shuffle the data in the STL container. The concrete implementation is as follows: random _ shuffle (vecip. begin (), vecip. end ()); after the function is called and completed, all the ips in the container are already shuffled, and after the shuffle, the subsequent strategy of this embodiment is to select 3 ips for linking each time, so that preferably a group of ips does not have the same port number, and if the group of ips has the same port number, the position of the group of ips can be exchanged with the subsequent ips.
And 7, linking the bullet screen server according to the random and disordered IP.
The existing approach is to attempt to link servers through individual ip and port. This may sometimes result in a longer off-link time consumption due to timeouts. In this embodiment, 3 ips are sequentially selected from the container to try to link, each ip is set to timeout of 4 seconds, and if one of the 3 ips is connected, the other 2 ips are immediately disconnected. First, when starting the link, the present embodiment initiates the first ip to link. Creating a network socket; establishing a connection with a server by using int socket (AF _ INET, socket _ STREAM, 0); creating an address family, servaddr.sin _ family ═ vecip [0]. ip; create a port number (host endian to network endian), servaddr.sin _ port ═ htons (vecip [0]. port); then, linking is performed, and int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr)); within 4 seconds, if the link returns, the connection is successful, the IP link speed is high and the IP link can be used, and then the link is carried out based on the IP; if the link has not returned success or failure after 4 seconds from the beginning, the embodiment will select the second ip from vecip for linking. int socket fd1 ═ socket (AF _ INET, socket _ STREAM,0) establishes a connection with the server; creating an address family, servaddr1.sin _ family ═ vecip [1]. ip; create a port number (host endian to network endian), servaddr1.sin _ port ═ htons (vecip [1]. port); then, linking is carried out, and int nRet ═ connect (sockfd1, (struct sockaddr) & servaddr1, sizeof (servaddr 1)); similarly, if 4 seconds pass, the link for opening the third ip is not returned; int socket fd2 ═ socket (AF _ INET, socket _ STREAM,0) establishes a connection with the server; creating an address family, servaddr2.sin _ family ═ vecip [2]. ip; create a port number (host endian to network endian), servaddr2.sin _ port ═ htons (vecip [2]. port); then the present embodiment opens 3 groups of ip links within 12 seconds, int nRet ═ connect (sockfd1, (struct sockaddr) & servaddr2, sizeof (servaddr 2)); if any link of the ip is returned, the embodiment will disconnect the other links of the ip. Therefore, the method also shows that the ip link line returned first is better and the link speed is higher.
In this embodiment, 3 ips are selected from the container in turn to try to link, which is faster than the conventional method to connect to the barrage server. The processing efficiency of linking barrage has been improved.
The above describes the embodiments of the present invention from the perspective of a method of linking a bullet screen, and the following describes the embodiments of the present invention from the perspective of a mobile terminal.
Referring to fig. 2, fig. 2 is a schematic diagram of an embodiment of a possible mobile terminal according to the present invention, including: the first processing unit 201 is configured to create data related to a socket and link the data with a barrage server; a first determining unit 202, configured to determine a socket breaker that is a network interrupt object, where the socket breaker is used to trigger the socket to interrupt a current link; a first creating unit 203, configured to create a selection object select of a network, where the select is used to monitor state information of the socket; a second creating unit 204, configured to create an event object event, where the event is used to notify the state information of the socket; a third creating unit 205, configured to create a Thread object Thread of the socket and an execution function void __ RunThread (), which executes the Thread; a fourth creating unit 206, configured to create while loop in the execution function to monitor the state of the socket; the reading unit 207 is configured to read data sent by the bullet screen server and received in the socket; and the sending unit 208 is configured to send data to be sent to the bullet screen server through the Socket.
Optionally, in some possible implementation manners, the third creating unit 205 is specifically configured to: creating a Thread object Thread of the socket; creating an execution function void __ RunThread (), wherein the execution function void __ RunThread () is used for executing the Thread; and binding a preset basic library Boost with the void __ RunThread (), and transferring the Boost to the void __ RunThread ().
Optionally, in some possible implementations, the second creating unit 204 is specifically configured to: creating an event.OnError (ConnectTimeouther) for the event object event, the event.OnError (ConnectTimeouther) to indicate a link timeout error; creating an event.OnError (ConnectionError) of the event object for calling OnError to notify the Socket of an error; creating an event.OnConnect () of the event object, the event.OnConnect () being used to notify the Socket link success.
Optionally, in some possible implementation manners, the first creating unit 203 is specifically configured to: creating a selection object select of the network; associating the socket with the select; associating the abnormal condition of the socket with the select; and associating the reading and writing of the socket with the select.
Optionally, in some possible implementation manners, the first processing unit 201 is specifically configured to: establishing connection with a server by creating int socket (AF _ INET, socket _ STREAM, 0); creating an address family servaddr. Create a port number (servaddr. sin _ port ═ htons (port)); creating a system function int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr)); and calling the int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) to link with the bullet screen server.
Optionally, in some possible implementations, the reading unit 207 is specifically configured to: judging whether the socket is in a Read set Read _ FD _ ISSET or not; if the socket is in the Read _ FD _ ISSET, calling event.OnRead () to inform that data in the socket can be Read; and reading the data sent by the bullet screen server and received in the socket.
Optionally, in some possible implementations, the sending unit 208 is specifically configured to: judging whether the socket is in a read set Write _ FD _ ISSET or not; if the socket is in the Write _ FD _ ISSET, calling event. And sending the data to be sent in the socket to the bullet screen server.
Referring to fig. 3, fig. 3 is a schematic diagram of an embodiment of an electronic device according to an embodiment of the invention.
As shown in fig. 3, an embodiment of the present invention provides an electronic device, which includes a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor 320, where the processor 320 executes the computer program 311 to implement the following steps: creating related data of the socket and linking the related data with the bullet screen server; determining a network interrupt object socket breaker, wherein the socket breaker is used for triggering the socket to interrupt the current link; creating a selection object select of a network, wherein the select is used for monitoring the state information of the socket; creating an event object event, wherein the event is used for notifying the state information of the socket; creating a Thread object Thread of the socket and an execution function void __ RunThread (), wherein the Thread object Thread executes the Thread; creating while loop in the execution function to monitor the state of the socket; reading data sent by the bullet screen server and received in the socket; and sending the data to be sent to the bullet screen server through the socket.
Optionally, in a possible embodiment, the processor is specifically configured to: creating a Thread object Thread of the socket; creating an execution function void __ RunThread (), wherein the execution function void __ RunThread () is used for executing the Thread; and binding a preset basic library Boost with the void __ RunThread (), and transferring the Boost to the void __ RunThread ().
Optionally, in a possible embodiment, the processor is specifically configured to: creating an event.OnError (ConnectTimeouther) for the event object event, the event.OnError (ConnectTimeouther) to indicate a link timeout error; creating an event.OnError (ConnectionError) of the event object for calling OnError to notify the Socket of an error; creating an event.OnConnect () of the event object, the event.OnConnect () being used to notify the Socket link success.
Optionally, in a possible embodiment, the processor is specifically configured to: creating a selection object select of the network; associating the socket with the select; associating the abnormal condition of the socket with the select; and associating the reading and writing of the socket with the select.
Optionally, in a possible embodiment, the processor is specifically configured to: establishing connection with a server by creating int socket (AF _ INET, socket _ STREAM, 0); creating an address family servaddr. Create a port number (servaddr. sin _ port ═ htons (port)); creating a system function int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr)); and calling the int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) to link with the bullet screen server.
Optionally, in a possible embodiment, the processor is specifically configured to: judging whether the socket is in a Read set Read _ FD _ ISSET or not; if the socket is in the Read _ FD _ ISSET, calling event.OnRead () to inform that data in the socket can be Read; and reading the data sent by the bullet screen server and received in the socket.
Optionally, in a possible embodiment, the processor is specifically configured to: judging whether the socket is in a read set Write _ FD _ ISSET or not; if the socket is in the Write _ FD _ ISSET, calling event. And sending the data to be sent in the socket to the bullet screen server.
In a specific implementation, when the processor 320 executes the computer program 311, any of the embodiments corresponding to fig. 1 may be implemented.
Referring to fig. 4, fig. 4 is a schematic diagram illustrating an embodiment of a computer-readable storage medium according to the present invention.
As shown in fig. 4, the present embodiment provides a computer-readable storage medium 400, on which a computer program 411 is stored, the computer program 411 implementing the following steps when executed by a processor: creating related data of the socket and linking the related data with the bullet screen server; determining a network interrupt object socket breaker, wherein the socket breaker is used for triggering the socket to interrupt the current link; creating a selection object select of a network, wherein the select is used for monitoring the state information of the socket; creating an event object event, wherein the event is used for notifying the state information of the socket; creating a Thread object Thread of the socket and an execution function void __ RunThread (), wherein the Thread object Thread executes the Thread; creating while loop in the execution function to monitor the state of the socket; reading data sent by the bullet screen server and received in the socket; and sending the data to be sent to the bullet screen server through the socket.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: creating a Thread object Thread of the socket; creating an execution function void __ RunThread (), wherein the execution function void __ RunThread () is used for executing the Thread; and binding a preset basic library Boost with the void __ RunThread (), and transferring the Boost to the void __ RunThread ().
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: creating an event.OnError (ConnectTimeouther) for the event object event, the event.OnError (ConnectTimeouther) to indicate a link timeout error; creating an event.OnError (ConnectionError) of the event object for calling OnError to notify the Socket of an error; creating an event.OnConnect () of the event object, the event.OnConnect () being used to notify the Socket link success.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: creating a selection object select of the network; associating the socket with the select; associating the abnormal condition of the socket with the select; and associating the reading and writing of the socket with the select.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: establishing connection with a server by creating int socket (AF _ INET, socket _ STREAM, 0); creating an address family servaddr. Create a port number (servaddr. sin _ port ═ htons (port)); creating a system function int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr)); and calling the int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) to link with the bullet screen server.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: judging whether the socket is in a Read set Read _ FD _ ISSET or not; if the socket is in the Read _ FD _ ISSET, calling event.OnRead () to inform that data in the socket can be Read; and reading the data sent by the bullet screen server and received in the socket.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: judging whether the socket is in a read set Write _ FD _ ISSET or not; if the socket is in the Write _ FD _ ISSET, calling event. And sending the data to be sent in the socket to the bullet screen server.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.

Claims (10)

1. A method of linking bullet screens, comprising:
creating related data of the socket and linking the related data with the bullet screen server;
determining a network interrupt object socket breaker, wherein the socket breaker is used for triggering the socket to interrupt the current link;
creating a selection object select of a network, wherein the select is used for monitoring the state information of the socket; the state information of the socket includes: abnormal state information, read-write state information;
creating an event object event, wherein the event is used for notifying the state information of the socket;
creating a Thread object Thread of the socket and an execution function void __ RunThread (), wherein the Thread object Thread executes the Thread;
creating while loop in the execution function to monitor the state of the socket;
reading data sent by the bullet screen server and received in the socket;
and sending the data to be sent to the bullet screen server through the socket.
2. The method as claimed in claim 1, wherein the creating of the Thread object Thread of the Socket and the executing function void __ RunThread () for executing the Thread comprises:
creating a Thread object Thread of the socket;
creating an execution function void __ RunThread (), wherein the execution function void __ RunThread () is used for executing the Thread;
and binding a preset basic library Boost with the void __ RunThread (), and transferring the Boost to the void __ RunThread ().
3. The method of claim 1, wherein the creating an event object event, the event for notifying the state information of the socket, comprises:
creating an event.OnError (ConnectTimeouther) for the event object event, the event.OnError (ConnectTimeouther) to indicate a link timeout error;
creating an event.OnError (ConnectionError) of the event object for calling OnError to notify the Socket of an error;
creating an event.OnConnect () of the event object, the event.OnConnect () being used to notify the Socket link success.
4. The method of claim 1, wherein a select object of the creation network is selected, and wherein the select is configured to monitor status information of the socket and comprises:
creating a selection object select of the network;
associating the socket with the select;
associating the abnormal condition of the socket with the select;
and associating the reading and writing of the socket with the select.
5. The method of claim 1, wherein the creating data related to the socket and linking with the bullet screen server comprises:
establishing connection with a server by creating int socket (AF _ INET, socket _ STREAM, 0);
creating an address family servaddr.
Create a port number (servaddr. sin _ port ═ htons (port));
creating a system function int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr));
and calling the int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) to link with the bullet screen server.
6. The method according to any one of claims 1 to 5, wherein the reading of the data sent by the bullet screen server received in the Socket comprises:
judging whether the socket is in a Read set Read _ FD _ ISSET or not;
if the socket is in the Read _ FD _ ISSET, calling event.
And reading the data sent by the bullet screen server and received in the socket.
7. The method according to any one of claims 1 to 5, wherein the sending the data to be sent to the bullet screen server through the socket comprises:
judging whether the socket is in a read set Write _ FD _ ISSET or not;
if the socket is in the Write _ FD _ ISSET, calling event.
And sending the data to be sent in the socket to the bullet screen server.
8. A mobile terminal, comprising:
the first processing unit is used for creating related data of the socket and linking the related data with the bullet screen server;
the system comprises a first determining unit, a second determining unit and a third determining unit, wherein the first determining unit is used for determining a socket breaker of a network interrupt object, and the socket breaker is used for triggering the socket to interrupt a current link;
the system comprises a first establishing unit, a selecting unit and a processing unit, wherein the first establishing unit is used for establishing a selection object select of a network, and the select is used for monitoring the state information of the socket; the state information of the socket includes: abnormal state information, read-write state information;
the second creating unit is used for creating an event object event, and the event is used for notifying the state information of the socket;
a third creating unit, configured to create a Thread object Thread of the socket and an execution function void __ RunThread (), which executes the Thread;
a fourth creating unit, configured to create while loop in the execution function to monitor the state of the socket;
the reading unit is used for reading the data received in the socket and sent by the bullet screen server;
and the sending unit is used for sending the data to be sent to the bullet screen server through the Socket.
9. A computer-readable storage medium comprising instructions that, when executed on a computer, cause the computer to perform the method of any of claims 1-7.
10. An electronic device comprising a memory, a processor, wherein the processor is configured to implement the method of any one of claims 1-7 when executing a computer management class program stored in the memory.
CN201811067037.0A 2018-09-13 2018-09-13 Bullet screen linking method and mobile terminal Active CN110896493B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811067037.0A CN110896493B (en) 2018-09-13 2018-09-13 Bullet screen linking method and mobile terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811067037.0A CN110896493B (en) 2018-09-13 2018-09-13 Bullet screen linking method and mobile terminal

Publications (2)

Publication Number Publication Date
CN110896493A CN110896493A (en) 2020-03-20
CN110896493B true CN110896493B (en) 2022-02-08

Family

ID=69785496

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811067037.0A Active CN110896493B (en) 2018-09-13 2018-09-13 Bullet screen linking method and mobile terminal

Country Status (1)

Country Link
CN (1) CN110896493B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115442635A (en) * 2021-06-04 2022-12-06 武汉斗鱼鱼乐网络科技有限公司 Method, device, equipment and storage medium for cross-platform security filtration of bullet screen

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101969455A (en) * 2010-09-13 2011-02-09 山东省农业科学院科技信息工程技术研究中心 Smartphone-based wheat production risk information acquisition system and method
CN102118325A (en) * 2010-11-30 2011-07-06 北京迅捷英翔网络科技有限公司 Method and device for configuring chat client terminal, as well as chat client terminal
CN103164256A (en) * 2011-12-08 2013-06-19 深圳市快播科技有限公司 Processing method and system capable of achieving one machine supporting high concurrency
CN108200170A (en) * 2018-01-02 2018-06-22 武汉斗鱼网络科技有限公司 Message treatment method, device and readable storage medium storing program for executing

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1306430C (en) * 2002-12-31 2007-03-21 上海科泰世纪科技有限公司 User self-defining event mechanism based on structure

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101969455A (en) * 2010-09-13 2011-02-09 山东省农业科学院科技信息工程技术研究中心 Smartphone-based wheat production risk information acquisition system and method
CN102118325A (en) * 2010-11-30 2011-07-06 北京迅捷英翔网络科技有限公司 Method and device for configuring chat client terminal, as well as chat client terminal
CN103164256A (en) * 2011-12-08 2013-06-19 深圳市快播科技有限公司 Processing method and system capable of achieving one machine supporting high concurrency
CN108200170A (en) * 2018-01-02 2018-06-22 武汉斗鱼网络科技有限公司 Message treatment method, device and readable storage medium storing program for executing

Also Published As

Publication number Publication date
CN110896493A (en) 2020-03-20

Similar Documents

Publication Publication Date Title
Burns Designing distributed systems: patterns and paradigms for scalable, reliable services
US6941341B2 (en) Method and apparatus for balancing distributed applications
US8706806B2 (en) Technique for enabling a plurality of software components to communicate in a software component matrix environment
US9524186B2 (en) System and method for supporting common transaction identifier (XID) optimization based on resource manager (RM) instance awareness in a transactional environment
US20070174815A1 (en) Decentralized system services
CN107592237B (en) Resource monitoring method and system of hybrid cloud
US20120173614A1 (en) Event broker for an improved application server platform for telecom-based applications
CN109379638B (en) Bullet screen linking method and mobile terminal
CN102025567A (en) Sharing access detection method and related device
CN110896493B (en) Bullet screen linking method and mobile terminal
Arad et al. Developing, simulating, and deploying peer-to-peer systems using the kompics component model
CN110896570B (en) Bullet screen linking method and mobile terminal
CN109275014B (en) Bullet screen linking method and mobile terminal
CN104969533B (en) A kind of data package processing method and device
CN109308202A (en) A kind of method and mobile terminal linking barrage
CN109379453B (en) Method and system for detecting IP address of DNS (Domain name Server) outlet server
Wang et al. A scalable queuing service based on an in-memory data grid
US11811804B1 (en) System and method for detecting process anomalies in a distributed computation system utilizing containers
US20230379391A1 (en) Systems and methods for header processing in a server computing environment
Narayan et al. Bringing Reconfigurability to the Network Stack
WO2023225219A2 (en) Systems and methods for header processing in a server computing environment
CN117544592A (en) Domain name resolution method, device, node, electronic equipment and storage medium
CN116866413A (en) Education account number and basic data linkage processing method and system
CN114064310A (en) Process communication method and system
CN114500681A (en) Network request connection method, device, medium and computer equipment

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
GR01 Patent grant
GR01 Patent grant