Bullet screen linking method and mobile terminal

文档序号:1436273 发布日期:2020-03-20 浏览:21次 中文

阅读说明:本技术 一种链接弹幕的方法及移动终端 (Bullet screen linking method and mobile terminal ) 是由 周志刚 于 2018-09-13 设计创作,主要内容包括:本发明公开了一种链接弹幕的方法及移动终端,用于对链接弹幕的过程进行了优化,提高了链接弹幕的效率。本发明方法包括:创建套接字socket的相关数据,并与弹幕服务器进行链接;确定网络中断对象SocketBreaker,SocketBreaker用于触发socket中断当前链接;创建网络的选择对象select,select用于监控socket的状态信息;创建事件对象event,event用于通知socket的状态信息;创建socket的线程对象Thread和执行Thread的执行函数void__RunThread();在执行函数中创建while循环监控socket的状态;读取socket中接收到的弹幕服务器发送的数据;将需要发送的数据通过socket发送至弹幕服务器。(The invention discloses a method for linking barrage and a mobile terminal, which are used for optimizing the process of linking the barrage and improving the efficiency of linking the barrage. The method comprises the following steps: creating related data of the socket and linking the related data with the bullet screen server; determining a network interrupt object socket breaker, wherein the socket breaker is used for triggering socket to interrupt the current link; creating a selection object select of the network, wherein the select is used for monitoring the state information of the socket; creating an event object event for notifying the state information of the socket; creating a Thread object Thread of socket and an execution function void __ RunThread (), which executes Thread; creating a while loop in an execution function to monitor the state of the socket; reading data sent by a bullet screen server received in a socket; and sending the data to be sent to the bullet screen server through the socket.)

1. A method of linking bullet screens, comprising:

creating related data of the socket and linking the related data with the bullet screen server;

determining a network interrupt object socket breaker, wherein the socket breaker is used for triggering the socket to interrupt the current link;

creating a selection object select of a network, wherein the select is used for monitoring the state information of the socket;

creating an event object event, wherein the event is used for notifying the state information of the socket;

creating a Thread object Thread of the socket and an execution function void __ RunThread (), wherein the Thread object Thread executes the Thread;

creating while loop in the execution function to monitor the state of the socket;

reading data sent by the bullet screen server and received in the socket;

and sending the data to be sent to the bullet screen server through the socket.

2. The method as claimed in claim 1, wherein the creating of the Thread object Thread of the Socket and the executing function void __ RunThread () for executing the Thread comprises:

creating a Thread object Thread of the socket;

creating an execution function void __ RunThread (), wherein the execution function void __ RunThread () is used for executing the Thread;

and binding a preset basic library Boost with the void __ RunThread (), and transferring the Boost to the void __ RunThread ().

3. The method of claim 1, wherein the creating an event object event, the event for notifying the state information of the socket, comprises:

creating an event.OnError (ConnectTimeouther) for the event object event, the event.OnError (ConnectTimeouther) to indicate a link timeout error;

creating an event.OnError (ConnectionError) of the event object for calling OnError to notify the Socket of an error;

creating an event.OnConnect () of the event object, the event.OnConnect () being used to notify the Socket link success.

4. The method of claim 1, wherein a select object of the creation network is selected, and wherein the select is configured to monitor status information of the socket and comprises:

creating a selection object select of the network;

associating the socket with the select;

associating the abnormal condition of the socket with the select;

and associating the reading and writing of the socket with the select.

5. The method of claim 1, wherein the creating data related to the socket and linking with the bullet screen server comprises:

establishing connection with a server by creating int socket (AF _ INET, socket _ STREAM, 0);

creating an address family servaddr.

Create a port number (servaddr. sin _ port ═ htons (port);

creating a system function int nRet ═ connect (sockfd, (struct sockaddr) & servaddr, sizeof (servaddr));

and calling the int nRet ═ connect (sock fd, (struct sock addr) & servadr, sizeof (servaddr)) to link with the bullet screen server.

6. The method according to any one of claims 1 to 5, wherein the reading of the data sent by the bullet screen server received in the Socket comprises:

judging whether the socket is in a Read set Read _ FD _ ISSET or not;

if the socket is in the Read _ FD _ ISSET, calling event.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.

7. The method according to any one of claims 1 to 5, wherein the sending the data to be sent to the bullet screen server through the socket comprises:

judging whether the socket is in a read set Write _ FD _ ISSET or not;

if the socket is in the Write _ FD _ ISSET, calling event.

And sending the data to be sent in the socket to the bullet screen server.

8. A mobile terminal, comprising:

the first processing unit is used for creating related data of the socket and linking the related data with the bullet screen server;

the system comprises a first determining unit, a second determining unit and a third determining unit, wherein the first determining unit is used for determining a socket breaker of a network interrupt object, and the socket breaker is used for triggering the socket to interrupt a current link;

the system comprises a first establishing unit, a selecting unit and a processing unit, wherein the first establishing unit is used for establishing a selection object select of a network, and the select is used for monitoring the state information of the socket;

the second creating unit is used for creating an event object event, and the event is used for notifying the state information of the socket;

a third creating unit, configured to create a Thread object Thread of the socket and an execution function void __ RunThread (), which executes the Thread;

a fourth creating unit, configured to create while loop in the execution function to monitor the state of the socket;

the reading unit is used for reading the data received in the socket and sent by the bullet screen server;

and the sending unit is used for sending the data to be sent to the bullet screen server through the Socket.

9. A computer-readable storage medium comprising instructions that, when executed on a computer, cause the computer to perform the method of any of claims 1-7.

10. A computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of any one of claims 1 to 7.

Technical Field

The invention relates to the field of terminals, in particular to a method for linking a bullet screen and a mobile terminal.

Background

With the rapid development of the internet technology, the functions of the mobile terminal are more and more abundant, and the barrage function for improving the user experience also appears on the mobile terminal.

In the conventional scheme, a pop-up screen scheme of a Personal Computer (PC) client is generally migrated to a mobile terminal. For the mobile terminal, the characteristics are that the network is unstable, a mobile 4G network is used, and the mobile terminal can move, for example, the mobile terminal moves to a place where the network signal is not good; or, switching from the 3G network to the 4G network; or, switching from the 4G network to a wireless fidelity (WIFI) network; or switching from WIFI to a 4G network, etc. Meanwhile, for the barrage link, due to various reasons of the client or account, the server may determine the validity of the client during the link, so as to return an error code and the like, and therefore the client needs to consider the error code of the server.

In the conventional scheme, for the bullet screen connection of the client of the mobile terminal to the server, only the usability of the function is considered, and the characteristics of the mobile terminal, such as unstable network, power consumption of the mobile terminal, heat generation and the like, are not considered. Therefore, the connection between the mobile terminal and the bullet screen server is easily interrupted, and the process of restoring the connection is slow.

Disclosure of Invention

The embodiment of the invention provides a method for linking bullet screens and a mobile terminal, which are used for optimizing the process of linking bullet screens and improving the processing efficiency of linking bullet screens.

A first aspect of an embodiment of the present invention provides a method for linking bullet screens, including: creating related data of the socket and linking the related data with the bullet screen server; determining a network interrupt object socket breaker, wherein the socket breaker is used for triggering the socket to interrupt the current link; creating a selection object select of a network, wherein the select is used for monitoring the state information of the socket; creating an event object event, wherein the event is used for notifying the state information of the socket; creating a Thread object Thread of the socket and an execution function void __ RunThread (), wherein the Thread object Thread executes the Thread; creating while loop in the execution function to monitor the state of the socket; reading data sent by the bullet screen server and received in the socket; and sending the data to be sent to the bullet screen server through the socket.

In one possible embodiment, the creating the Thread object Thread of the socket and the executing function void __ RunThread () of executing the Thread include: creating a Thread object Thread of the socket; creating an execution function void __ RunThread (), wherein the execution function void __ RunThread () is used for executing the Thread; and binding a preset basic library Boost with the void __ RunThread (), and transferring the Boost to the void __ RunThread ().

In one possible embodiment, the creating an event object event, where the event is used to notify the socket of the status information includes: creating an event.OnError (ConnectTimeouther) for the event object event, the event.OnError (ConnectTimeouther) to indicate a link timeout error; creating an event.OnError (ConnectionError) of the event object for calling OnError to notify the Socket of an error; creating an event.OnConnect () of the event object, the event.OnConnect () being used to notify the socket link success.

In a possible embodiment, the creating a selection object of the network, the selection object being used for monitoring the state information of the socket, includes: creating a selection object select of the network; associating the socket with the select; associating the abnormal condition of the socket with the select; and associating the reading and writing of the socket with the select.

In a possible embodiment, the creating data related to the socket and linking with the bullet screen server includes: establishing connection with a server by creating int socket (AF _ INET, socket _ STREAM, 0); creating an address family servaddr. Creating a port number (servaddr) and creating a system function int nRet ═ connect (sockfd), (struct sockaddr) & servadr, sizeof (servaddr)), and calling the int nRet ═ connect (sockfd, (struct sockaddr) & servadr, sizeof (servaddr)) to link with the bullet screen server.

In a possible embodiment, the reading the data sent by the bullet screen server received in the socket includes: judging whether the socket is in a Read set Read _ FD _ ISSET or not; if the socket is in the Read _ FD _ ISSET, calling event.OnRead () to inform that data in the socket can be Read; and reading the data sent by the bullet screen server and received in the socket.

In a possible embodiment, the sending the data to be sent to the bullet screen server through the socket includes: judging whether the socket is in a read set Write _ FD _ ISSET or not; if the socket is in the Write _ FD _ ISSET, calling event. And sending the data to be sent in the socket to the bullet screen server.

A second aspect of an embodiment of the present invention provides a mobile terminal, including: the first processing unit is used for creating related data of the socket and linking the related data with the bullet screen server; the system comprises a first determining unit, a second determining unit and a third determining unit, wherein the first determining unit is used for determining a socket breaker of a network interrupt object, and the socket breaker is used for triggering the socket to interrupt a current link; the system comprises a first establishing unit, a selecting unit and a processing unit, wherein the first establishing unit is used for establishing a selection object select of a network, and the select is used for monitoring the state information of the socket; the second creating unit is used for creating an event object event, and the event is used for notifying the state information of the socket; a third creating unit, configured to create a Thread object Thread of the socket and an execution function void __ RunThread (), which executes the Thread; a fourth creating unit, configured to create while loop in the execution function to monitor the state of the socket; the reading unit is used for reading the data received in the socket and sent by the bullet screen server; and the sending unit is used for sending the data to be sent to the bullet screen server through the socket.

A third aspect of the present invention provides an electronic device, comprising a memory and a processor, wherein the processor is configured to implement the steps of the method for linking a bullet screen according to any one of the above first aspects when executing a computer management program stored in the memory.

A fourth aspect of the present application provides a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to perform the method of the above-described aspects.

A fifth aspect of the present application provides a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of the above-described aspects.

Drawings

Fig. 1 is a flowchart of a method for linking bullet screens according to an embodiment of the present invention;

fig. 2 is a schematic structural diagram of a mobile terminal according to an embodiment of the present invention;

fig. 3 is a schematic diagram of a hardware structure of a possible electronic device according to an embodiment of the present invention;

fig. 4 is a schematic hardware structure diagram of a possible computer-readable storage medium according to an embodiment of the present invention.

Detailed Description

The embodiment of the invention provides a method for linking bullet screens and a mobile terminal, which are used for optimizing the process of linking bullet screens and improving the efficiency of linking bullet screens.

The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

The terms "first," "second," "third," "fourth," and the like in the description and in the claims of the present application and in the drawings described above, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be practiced otherwise than as specifically illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.

30页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种多面体桌面媒体广告装置及其群组管理系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类