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

Bullet screen linking method and mobile terminal Download PDF

Info

Publication number
CN110896570B
CN110896570B CN201811067413.6A CN201811067413A CN110896570B CN 110896570 B CN110896570 B CN 110896570B CN 201811067413 A CN201811067413 A CN 201811067413A CN 110896570 B CN110896570 B CN 110896570B
Authority
CN
China
Prior art keywords
network
class
current
state
type
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
CN201811067413.6A
Other languages
Chinese (zh)
Other versions
CN110896570A (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 CN201811067413.6A priority Critical patent/CN110896570B/en
Publication of CN110896570A publication Critical patent/CN110896570A/en
Application granted granted Critical
Publication of CN110896570B publication Critical patent/CN110896570B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W76/00Connection management
    • H04W76/10Connection setup
    • H04W76/19Connection re-establishment
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • H04L43/0805Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
    • H04L43/0817Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking functioning
    • 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/43Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
    • H04N21/431Generation of visual interfaces for content selection or interaction; Content or additional data rendering
    • H04N21/4312Generation of visual interfaces for content selection or interaction; Content or additional data rendering involving specific graphical features, e.g. screen layout, special fonts or colors, blinking icons, highlights or animations
    • H04N21/4314Generation of visual interfaces for content selection or interaction; Content or additional data rendering involving specific graphical features, e.g. screen layout, special fonts or colors, blinking icons, highlights or animations for fitting data in a restricted space on the screen, e.g. EPG data in a rectangular grid
    • 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/43Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
    • H04N21/442Monitoring of processes or resources, e.g. detecting the failure of a recording device, monitoring the downstream bandwidth, the number of times a movie has been viewed, the storage space available from the internal hard disk
    • H04N21/44227Monitoring of local network, e.g. connection or bandwidth variations; Detecting new devices in the local network
    • 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/478Supplemental services, e.g. displaying phone caller identification, shopping application
    • H04N21/4788Supplemental services, e.g. displaying phone caller identification, shopping application communicating with other users, e.g. chatting
    • 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
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Abstract

The invention discloses a method for linking bullet screens and a mobile terminal, which are used for setting overtime for a longer time, reducing the power consumption and improving the processing efficiency of linking bullet screens. The method comprises the following steps: defining a network link type to store the current network type and generating a status code of the network type; generating a monitoring class of a network state in an Android system, wherein the network state monitoring class comprises a subclass NetworkChange class which is inherited to a BroadcastReceiver class of the system; instantiating the monitoring class and registering the system, instantiating the NetworkChange class and calling a register receiver function of the system to register network monitoring; monitoring the state code of the network type through a register receiver function, and linking a bullet screen server according to the change condition of the state code; if the current state code is the same as the previous state code, keeping the current barrage link unchanged; and if the current state code is different from the previous state code, adjusting the network according to the current state change.

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 setting overtime for a longer time and reconnecting through a bottom layer network, so that the power consumption is reduced, and the processing efficiency of the linked bullet screens is improved.
A first aspect of an embodiment of the present invention provides a method for linking bullet screens, including: defining a network link type to store the current network type and generating a status code of the network type; generating a monitoring class of a network state in an Android system, wherein the network state monitoring class comprises a subclass NetworkChange class which is inherited to a BroadcastReceiver class of the system; instantiating the monitoring class and registering a system, wherein the NetworkChange class is instantiated and a register receiver function of the system is called to register network monitoring; monitoring the state code of the network type through the register receiver function; if the current state code is the same as the previous state code and the network state is not changed, keeping the current bullet screen link unchanged; if the current status code is different from the previous status code and the network status changes, the network is adjusted according to the current status change and linked with the bullet screen server, a variable NetStatus prevStatus is kNONET is defined, and the value of the variable NetStatus prevStatus is initialized to be in a state without the network.
In one possible embodiment, the defining a network link type to store the current network type and generating the status code of the network type includes: determining an enumeration variable NetStatus to store the network type, wherein the NetStatus comprises kNONET for indicating that no network exists currently, kWIFI for indicating that the current network is WIFI, and k4G for indicating that the current network is a 4G network; assigning the kNONET, the kWIFI and the k4G as 1, 2 and 3 respectively.
In a possible embodiment, the generating a monitoring class of a network state in an Android system, the network state monitoring class including a subclass NetworkChange class, and the NetworkChange class inheriting a broadcastreecepter class of the system includes: generating a monitoring class public class network change extensions BroadcastReceiver; a heavy-duty interface to receive network changes; judging whether a network is connected currently; judging the current network state through the ConnectiontManager attribute; defining a NetworkInfo object info and acquiring current network information.
In a possible embodiment, the defining a NetworkInfo object info and acquiring current network information includes: acquiring current NETWORK information through a system function getparamebleExtra, wherein the incoming parameter is connectitvytManager.EXTRA _ NETWORK _ INFO; and judging whether the current network is a WIFI network or a 4G network or has no network.
In a possible embodiment, the determining that the current network is a WIFI network, a 4G network, or no network includes: the current network type can be obtained through an interface getType of info; if the network type is connectivitymanager, type _ WIFI, setting the network status type to a WIFI network; type _ MOBILE, if the network type is connectivitymanager, setting the network status type to 4G network; and if no network exists currently, setting the network state type to be in a disconnection state.
In one possible embodiment, the instantiating the monitoring class and the system registering, wherein instantiating the NetworkChange class and calling a register receiver function of the system to register network monitoring comprises: creating an interface IntentFilter () as new IntentFilter (); calling addAction function of IntentFilter, and setting the incoming parameter as ConnectiontManager.CONNECTIVITY _ ACTION; instantiating the NetworkChange class to get a NetworkChange net (); the system's register receiver function is called to register network monitoring.
In a possible embodiment, the changing of the network as a function of a change in the current state, the variable NetStatus prevStatus kNONET being defined at program start-up and the initializing of its value to a network-free state comprises: call function pipe break () to disconnect the current network link; a function int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) is called for network linking.
A second aspect of an embodiment of the present invention provides a mobile terminal, including: the definition unit is used for defining a network link type to store the current network type and generating a state code of the network type; the system comprises a generating unit, a monitoring unit and a judging unit, wherein the generating unit is used for generating a monitoring class of a network state in an Android system, the network state monitoring class comprises a subclass NetworkChange class, and the NetworkChange class is inherited to a BroadcastReceiver class of the system; the registration unit is used for instantiating the monitoring class and registering the system, wherein the NetworkChange class is instantiated and a register receiver function of the system is called to register network monitoring; the monitoring unit is used for monitoring the state code of the network type through the register receiver function; the holding unit is used for holding the current bullet screen link unchanged if the current state code is the same as the previous state code and the network state is not changed; and the adjusting unit is used for adjusting the network according to the current state change and linking the bullet screen server if the current state code is different from the previous state code, defining a variable NetStatus prevStatus-kNONET, and initializing the value of the variable NetStatus prevStatus-kNONET to be in a state without the network.
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 setting overtime for a longer time and reconnecting through a bottom layer network, so that the power consumption is reduced, and the processing efficiency of the linked bullet screens is improved.
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 a bullet screen according to an embodiment of the present invention is shown, where network switching of a current network environment is monitored, and a reconnection design link scheme is performed based on a monitoring result, and the specific embodiment is 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:
101. a network link type is defined to store a current network type and a status code for the network type is generated.
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.
102. And 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 ()) (connectivity type manager, type _ MOBILE) { if the current link is not WIFI, continue to judge whether the type is connectivity type manager, type _ MOBILE, if yes, indicate that the current link is a 4G network of the MOBILE phone.
curStatus=k4G;
Else { no network is currently available, then it is in the network disconnected state.
curStatus=kNONET;
}
}
}
}
103. And 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.
104. The status code of the network type is monitored by a register receiver function.
Some adjustments to the bullet screen links are then needed depending on current network changes. We monitor the network for the current network status, and then this embodiment compares it with the previous network status.
105. And if the current state code is the same as the previous state code and the network state is not changed, keeping the current bullet screen link unchanged.
And if the network state is not changed, keeping the current barrage link unchanged, namely not operating the linked barrage.
106. And if the current state code is different from the previous state code and the network state changes, adjusting the network according to the current state change and linking the bullet screen server.
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) { if the current network status is the same as the previous network status, it indicates that the network has not changed, the bullet screen link does not change.
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));
the method includes the steps of (1) else if the current state is WIFI, changing the current network state, and if the current state is a 4G network, disconnecting the existing barrage link as soon as possible and using a new network to re-link. 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 it was previously belonging to a 4g network and now WIFI, it would also be necessary to immediately disconnect the network and re-link the new network. 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 strong signal network is switched to the no-signal network or weak signal network, the network bottom layer is reconnected overtime, and the overtime of longer time is set, 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 two
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 socket client program, and specific embodiments are as follows:
step 1, creating related data of a socket and linking with a 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) & servadrr, sizof (servaddr)).
And step 2, determining a network interrupt object socketstarter.
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.
And 3, creating a selection object select of the network.
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.
And 4, creating an event object event.
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.
And step 5, creating a Thread object Thread of the socket and an execution function void __ RunThread () for executing the 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 ().
And 6, creating a while loop monitoring socket state in the execution function.
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 (0 ═ selectRet) { denotes that there is no writable data in the current unreadable data, and there is no exception, then directly return to wait for the next state, continue; }
if (0> selectRet) { indicating that the current socket generates an exception, using event object event to inform the upper layer of the current IO read-write error, event.
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; }
And 7, reading the 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 (); }
And 8, 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. The method comprises the steps of creating a port number (servaddr), creating a system function (int nRet ═ connect, (struct sockaddr) & servadr, sizeof (servaddr)), calling the int nRet ═ connect, (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr)), and linking 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 III
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 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 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[kSocketThreadStart]=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[kSocketThreadStartErr]=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[kTcpConnectIpErr]=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[kTcpConnectTimeoutErr]=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[kTcpIOErr]=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[kTcpDisConnected]=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 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 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.
A subscriber generating a server error message, class error MessageObserver: public MessageObserver { it must implement all abstract interface functions of MessageObserver, public: consst std:: set < std:: string > & GetObserverMessageType () { first defining a static container object type, static std:: string > types; return directly if typehas stored all messages that need subscription. if (| types. empty ()) { return types; else no subscribed message, 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 method includes that a message subscription and distribution management module receives an error message, and then calls an interface to distribute the error message to a subscriber, wherein the message subscription and distribution management module is an error message subscriber, and then receives all error messages sent by a server, and then the error message is a corresponding popup 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. maprotate [ KDisconnect ] ═ true; maprotate [ kDataError ] ═ true; mapreduce [ kIOError ] ═ true; for non-reconnect operations the following are:
the enum NotRetryCode { kTick ═ 500 indicates that the error code is 500, and since the same account number logs in a plurality of devices and simultaneously logs in the same live broadcast room, 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.
itr=mapRetry.find(errorcode);
The query is then made using the error code obtained from the error message.
if(itr==mapRetry.end()){
Indicating 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(errorcode==800){
where the error code 800 indicates a room number error, the client may obtain 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(errorcode==900){
the error code 900 indicates that the token currently linked is invalid, at this time, the correct method is to request the token again and then reconnect the token, at this time, the client uses the HTTP request to obtain a new token, and performs the barrage linking after obtaining the new token.
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 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 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, it is necessary to define the abstract interface class MessageObserver, of the message subscriber
{ 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 seven
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 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.6 port:4002 ip2:118.34.32.7 port:4002 ip3:120.45.33.1 port:4008 ip4:121.55.23.8 port:2009 ip5:130.55.23.8 port: 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; in this embodiment, a container object is defined to store the acquired ip and ipsortem items;
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:
a defining unit 201, configured to define a network link type to store a current network type and generate a status code of the network type; a generating unit 202, configured to generate a monitoring class of a network state in an Android system, where the network state monitoring class includes a subclass NetworkChange class, and the NetworkChange class is inherited to a broadcastrechiver class of the system; a registering unit 203, configured to instantiate the monitoring class and register a system, where the NetworkChange class is instantiated and a register receiver function of the system is called to register network monitoring; a monitoring unit 204, configured to monitor the status code of the network type through the register receiver function; a holding unit 205, configured to hold the current bullet screen link unchanged if the current status code is the same as the previous status code and the network status is not changed; if the current status code is different from the previous status code and the network status changes, the adjusting unit 206 is configured to adjust the network according to the current status change and link the bullet screen server, define a variable NetStatus prevStatus ═ kNONET, and initialize the value to the status without the network.
Optionally, in some possible implementations, the definition unit 201 is specifically configured to: determining an enumeration variable NetStatus to store the network type, wherein the NetStatus comprises kNONET for indicating that no network exists currently, kWIFI for indicating that the current network is WIFI, and k4G for indicating that the current network is a 4G network; assigning the kNONET, the kWIFI and the k4G as 1, 2 and 3 respectively.
Optionally, in some possible implementations, the generating unit 202 is specifically configured to: generating a monitoring class public class network change extensions BroadcastReceiver; a heavy-duty interface to receive network changes; judging whether a network is connected currently; judging the current network state through the ConnectiontManager attribute; defining a NetworkInfo object info and acquiring current network information.
Optionally, in some possible implementations, the generating unit 202 is further specifically configured to: acquiring current NETWORK information through a system function getparamebleExtra, wherein the incoming parameter is connectitvytManager.EXTRA _ NETWORK _ INFO; and judging whether the current network is a WIFI network or a 4G network or has no network.
Optionally, in some possible implementations, the generating unit 202 is further specifically configured to: the current network type can be obtained through an interface getType of info; if the network type is connectivitymanager, type _ WIFI, setting the network status type to a WIFI network; type _ MOBILE, if the network type is connectivitymanager, setting the network status type to 4G network; and if no network exists currently, setting the network state type to be in a disconnection state.
Optionally, in some possible implementation manners, the registration unit 203 is specifically configured to: creating an interface IntentFilter () as new IntentFilter (); calling addAction function of IntentFilter, and setting the incoming parameter as ConnectiontManager.CONNECTIVITY _ ACTION; instantiating the NetworkChange class to get a NetworkChange net (); the system's register receiver function is called to register network monitoring.
Optionally, in some possible implementations, the adjusting unit 206 is specifically configured to: call function pipe break () to disconnect the current network link; a function int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) is called for network linking.
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 320 and executable on the processor 320, where the processor 320 executes the computer program 311 to implement the following steps: defining a network link type to store the current network type and generating a status code of the network type; generating a monitoring class of a network state in an Android system, wherein the network state monitoring class comprises a subclass NetworkChange class which is inherited to a BroadcastReceiver class of the system; instantiating the monitoring class and registering a system, wherein the NetworkChange class is instantiated and a register receiver function of the system is called to register network monitoring; monitoring the state code of the network type through the register receiver function; if the current state code is the same as the previous state code and the network state is not changed, keeping the current bullet screen link unchanged; if the current status code is different from the previous status code and the network status changes, the network is adjusted according to the current status change and linked with the bullet screen server, a variable NetStatus prevStatus is kNONET is defined, and the value of the variable NetStatus prevStatus is initialized to be in a state without the network.
Optionally, in a possible embodiment, the processor is specifically configured to: determining an enumeration variable NetStatus to store the network type, wherein the NetStatus comprises kNONET for indicating that no network exists currently, kWIFI for indicating that the current network is WIFI, and k4G for indicating that the current network is a 4G network; assigning the kNONET, the kWIFI and the k4G as 1, 2 and 3 respectively.
Optionally, in a possible embodiment, the processor is specifically configured to: generating a monitoring class public class network change extensions BroadcastReceiver; a heavy-duty interface to receive network changes; judging whether a network is connected currently; judging the current network state through the ConnectiontManager attribute; defining a NetworkInfo object info and acquiring current network information.
Optionally, in a possible embodiment, the processor is specifically configured to: acquiring current NETWORK information through a system function getparamebleExtra, wherein the incoming parameter is connectitvytManager.EXTRA _ NETWORK _ INFO; and judging whether the current network is a WIFI network or a 4G network or has no network.
Optionally, in a possible embodiment, the processor is specifically configured to: creating an interface IntentFilter () as new IntentFilter (); calling addAction function of IntentFilter, and setting the incoming parameter as ConnectiontManager.CONNECTIVITY _ ACTION; instantiating the NetworkChange class to get a NetworkChange net (); the system's register receiver function is called to register network monitoring.
Optionally, in a possible embodiment, the processor is specifically configured to: call function pipe break () to disconnect the current network link; a function int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) is called for network linking.
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: defining a network link type to store the current network type and generating a status code of the network type; generating a monitoring class of a network state in an Android system, wherein the network state monitoring class comprises a subclass NetworkChange class which is inherited to a BroadcastReceiver class of the system; instantiating the monitoring class and registering a system, wherein the NetworkChange class is instantiated and a register receiver function of the system is called to register network monitoring; monitoring the state code of the network type through the register receiver function; if the current state code is the same as the previous state code and the network state is not changed, keeping the current bullet screen link unchanged; if the current status code is different from the previous status code and the network status changes, the network is adjusted according to the current status change and linked with the bullet screen server, a variable NetStatus prevStatus is kNONET is defined, and the value of the variable NetStatus prevStatus is initialized to be in a state without the network.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: determining an enumeration variable NetStatus to store the network type, wherein the NetStatus comprises kNONET for indicating that no network exists currently, kWIFI for indicating that the current network is WIFI, and k4G for indicating that the current network is a 4G network; assigning the kNONET, the kWIFI and the k4G as 1, 2 and 3 respectively.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: generating a monitoring class public class network change extensions BroadcastReceiver; a heavy-duty interface to receive network changes; judging whether a network is connected currently; judging the current network state through the ConnectiontManager attribute; defining a NetworkInfo object info and acquiring current network information.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: acquiring current NETWORK information through a system function getparamebleExtra, wherein the incoming parameter is connectitvytManager.EXTRA _ NETWORK _ INFO; and judging whether the current network is a WIFI network or a 4G network or has no network.
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 interface IntentFilter () as new IntentFilter (); calling addAction function of IntentFilter, and setting the incoming parameter as ConnectiontManager.CONNECTIVITY _ ACTION; instantiating the NetworkChange class to get a NetworkChange net (); the system's register receiver function is called to register network monitoring.
Optionally, in a possible embodiment, the computer program 411 is specifically adapted to implement the following steps when being executed by a processor: call function pipe break () to disconnect the current network link; a function int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) is called for network linking.
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 (9)

1. A method of linking bullet screens, comprising:
defining a network link type to store the current network type and generating a state code of the network type, wherein the network link type is an enumeration type defined by an enum keyword;
generating a monitoring class of a network state in an Android system, wherein the network state monitoring class comprises a subclass NetworkChange class which is inherited to a BroadcastReceiver class of the system;
instantiating the monitoring class and registering a system, wherein the NetworkChange class is instantiated and a register receiver function of the system is called to register network monitoring;
monitoring the state code of the network type through the register receiver function;
if the current state code is the same as the previous state code and the network state is not changed, keeping the current bullet screen link unchanged;
if the current state code is different from the previous state code and the network state changes, the network is adjusted and the bullet screen server is linked according to the current state change, a variable NetStatus prevStatus kNONET is defined and the value of the variable NetStatus prevStatus kNONET is initialized to be in a state without the network, when the network is switched to a network without signals or a network with weak signals from a network with signals or a network with strong signals, the network bottom layer is reconnected by using overtime, and the network bottom layer is reconnected by setting overtime for a longer time.
2. The method of claim 1, wherein defining a network link type to store a current network type and generating a status code for the network type comprises:
determining an enumeration variable NetStatus to store the network type, wherein the NetStatus comprises kNONET for indicating that no network exists currently, kWIFI for indicating that the current network is WIFI, and k4G for indicating that the current network is a 4G network;
assigning the kNONET, the kWIFI and the k4G as 1, 2 and 3 respectively.
3. The method of claim 1, wherein generating the monitoring class of the network state in the Android system, the network state monitoring class comprising a subclass NetworkChange class, and wherein inheriting the NetworkChange class to a broadcastrechiver class of the system comprises:
generating a monitoring class public class network change extensions BroadcastReceiver;
a heavy-duty interface to receive network changes;
judging whether a network is connected currently;
judging the current network state through the ConnectiontManager attribute;
defining a NetworkInfo object info and acquiring current network information.
4. The method of claim 3, wherein defining a networklnfo object info and obtaining current network information comprises:
acquiring current NETWORK information through a system function getparamebleExtra, wherein the incoming parameter is connectitvytManager.EXTRA _ NETWORK _ INFO;
and judging whether the current network is a WIFI network or a 4G network or has no network.
5. The method of claim 4, wherein the determining that the current network is a WIFI network, a 4G network, or no network comprises:
the current network type can be obtained through an interface getType of info;
if the network type is connectivitymanager, type _ WIFI, setting the network status type to a WIFI network;
type _ MOBILE, if the network type is connectivitymanager, setting the network status type to 4G network;
and if no network exists currently, setting the network state type to be in a disconnection state.
6. The method of any of claims 1-5, wherein instantiating the monitoring class and registering the system, wherein instantiating the NetworkChange class and calling a system's register receiver function to register network monitoring comprises:
creating an interface IntentFilter () as new IntentFilter ();
calling addAction function of IntentFilter, and setting the incoming parameter as ConnectiontManager.CONNECTIVITY _ ACTION;
instantiating the NetworkChange class to get a NetworkChange net ();
the system's register receiver function is called to register network monitoring.
7. Method according to any of claims 1-5, characterized in that the changing of the network according to the current state change, the defining of the variable NetStatus prevStatus kNONET at program start-up and the initialization of its value to the state without network comprises:
call function pipe break () to disconnect the current network link;
a function int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) is called for network linking.
8. A mobile terminal, comprising:
the system comprises a defining unit, a judging unit and a judging unit, wherein the defining unit is used for defining a network link type to store the current network type and generating a state code of the network type, and the network link type is an enumeration type defined by an enum keyword;
the system comprises a generating unit, a monitoring unit and a judging unit, wherein the generating unit is used for generating a monitoring class of a network state in an Android system, the network state monitoring class comprises a subclass NetworkChange class, and the NetworkChange class is inherited to a BroadcastReceiver class of the system;
the registration unit is used for instantiating the monitoring class and registering the system, wherein the NetworkChange class is instantiated and a register receiver function of the system is called to register network monitoring;
the monitoring unit is used for monitoring the state code of the network type through the register receiver function;
the holding unit is used for holding the current bullet screen link unchanged if the current state code is the same as the previous state code and the network state is not changed;
and the adjusting unit is used for adjusting the network and linking the bullet screen server according to the change of the current state if the current state code is different from the previous state code, defining a variable NetStatus prevStatus which is kNONET, initializing the value of the variable NetStatus prevStatus which is kNONET into a network-free state, and when the network is switched to a signal-free network or a weak signal network from the network-free or strong signal network, using the overtime reconnection of the network bottom layer, and setting the overtime of longer time to reconnect the bottom layer network.
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.
CN201811067413.6A 2018-09-13 2018-09-13 Bullet screen linking method and mobile terminal Active CN110896570B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811067413.6A CN110896570B (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
CN201811067413.6A CN110896570B (en) 2018-09-13 2018-09-13 Bullet screen linking method and mobile terminal

Publications (2)

Publication Number Publication Date
CN110896570A CN110896570A (en) 2020-03-20
CN110896570B true CN110896570B (en) 2021-11-09

Family

ID=69785575

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811067413.6A Active CN110896570B (en) 2018-09-13 2018-09-13 Bullet screen linking method and mobile terminal

Country Status (1)

Country Link
CN (1) CN110896570B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106411636A (en) * 2016-09-08 2017-02-15 深圳怡化电脑股份有限公司 Method and system for monitoring status of self-service terminal and monitoring server
CN106982442A (en) * 2016-01-15 2017-07-25 深圳市朗驰欣创科技股份有限公司 A kind of method that radio communication is carried out in tunnel, apparatus and system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8606911B2 (en) * 2009-03-02 2013-12-10 Headwater Partners I Llc Flow tagging for service policy implementation
US8782269B2 (en) * 2010-12-22 2014-07-15 Verizon Patent And Licensing Inc. Auto-discovery of home and out-of-franchise networks

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106982442A (en) * 2016-01-15 2017-07-25 深圳市朗驰欣创科技股份有限公司 A kind of method that radio communication is carried out in tunnel, apparatus and system
CN106411636A (en) * 2016-09-08 2017-02-15 深圳怡化电脑股份有限公司 Method and system for monitoring status of self-service terminal and monitoring server

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
安卓通过广播实时监听当前网络状况;梦想blog;《CSDN》;20161213;正文第1-4页 *

Also Published As

Publication number Publication date
CN110896570A (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
US8555242B2 (en) Decentralized system services
CN109347998B (en) Method and system for detecting IP address of DNS (Domain name Server) outlet server
US8706806B2 (en) Technique for enabling a plurality of software components to communicate in a software component matrix environment
US20120173614A1 (en) Event broker for an improved application server platform for telecom-based applications
EP1949595A2 (en) Method for the construction and execution of a distributed workflow in a communication system
CN102025567A (en) Sharing access detection method and related device
CN109379638B (en) Bullet screen linking method and mobile terminal
CN114448895A (en) Application access method, device, equipment and medium
CN110896493B (en) Bullet screen linking method and mobile terminal
CN113626225B (en) Program calling method, terminal device and medium
US6842781B1 (en) Download and processing of a network management application on a network device
CN110896570B (en) Bullet screen linking method and mobile terminal
CN109275014B (en) Bullet screen linking method and mobile terminal
CN107105004B (en) Cross-platform service calling method and device
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
US20230379391A1 (en) Systems and methods for header processing in a server computing environment
Narayan et al. Bringing Reconfigurability to the Network Stack
US11811804B1 (en) System and method for detecting process anomalies in a distributed computation system utilizing containers
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

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