CN108696537A - Long connection network data distribution and processing method and system in IOS systems - Google Patents

Long connection network data distribution and processing method and system in IOS systems Download PDF

Info

Publication number
CN108696537A
CN108696537A CN201810745083.5A CN201810745083A CN108696537A CN 108696537 A CN108696537 A CN 108696537A CN 201810745083 A CN201810745083 A CN 201810745083A CN 108696537 A CN108696537 A CN 108696537A
Authority
CN
China
Prior art keywords
network data
network
ios
application layer
long connection
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.)
Granted
Application number
CN201810745083.5A
Other languages
Chinese (zh)
Other versions
CN108696537B (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 CN201810745083.5A priority Critical patent/CN108696537B/en
Publication of CN108696537A publication Critical patent/CN108696537A/en
Application granted granted Critical
Publication of CN108696537B publication Critical patent/CN108696537B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/04Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks
    • H04L63/0428Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks wherein the data content is protected, e.g. by encrypting or encapsulating the payload
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/55Push-based network services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/30Definitions, standards or architectural aspects of layered protocol stacks
    • H04L69/32Architecture of open systems interconnection [OSI] 7-layer type protocol stacks, e.g. the interfaces between the data link level and the physical level
    • H04L69/322Intralayer communication protocols among peer entities or protocol data unit [PDU] definitions
    • H04L69/329Intralayer communication protocols among peer entities or protocol data unit [PDU] definitions in the application layer [OSI layer 7]

Abstract

The invention discloses long connection network data distribution and processing method and system in a kind of IOS systems, are related to Communication Control Technology FIELD OF THE INVENTIONThe, method includes:The transmitting-receiving of the network data of long connection is carried out using the network interface layer of C++ written in code IOS system clients;The network data received is decrypted and is unpacked;The network data that C++ layer networks receive is transmitted to the object-c code layers of application layer;Network data is pushed to by object-c code layers in the application layer of IOS.Application layer is only needed to handle the distribution of type of message and be handled different type of messages, and for received message, and decryption message is then all realized by C++ bottom codes, and the long and is exactly the improved efficiency so that the development process of IOS application layers becomes simple.On the other hand, the characteristic that cross-system platform can be provided is write using C++ codes, can used in the system platforms such as such as Android, Windows, linux, IOS.It is corresponding to also disclose corresponding system.

Description

Long connection network data distribution and processing method and system in IOS systems
Technical field
The invention belongs to a kind of Communication Control Technology fields, more particularly relate to one kind and are grown in IOS system platforms The distribution of the network data of connection and processing method.
Background technology
Currently, popularizing with Apple Inc. IOS (iMac) smart mobile phone, corresponding to be adapted to IOS systematic difference journeys Sequence is also more and more abundant.The function of program is more and more, also necessarily means that the complexity of program is also higher and higher.
Specifically, for ios device, device hardware is restricted, so the program development for IOS systems For personnel, needs constantly to optimize its performance, improve its execution efficiency.Any one IOS application program can all have network logical Telecommunication function, for network direct broadcasting APP, a typical network communicating function is exactly to receive and dispatch bullet by network communication Curtain message.
For the very big application of size of message (such as now very hot internet video live broadcasting application), because network is logical The data volume of letter is very big, so optimizing reception distribution and the processing procedure of its internet message, improves the execution of code in program Efficiency, especially under actual environment, multiple systems (IOS apple systems, Android Android systems, Windows systems) are altogether It is stored in the same network, improves the collaboration capabilities of the application program for the closed IOS apple systems that compare and cross-platform energy Power is extremely important for application developer.
For the network data of long connection, it is suitable for TCP network connections (four layer models, the 4th layer of application layer, third layer Transport layer, second layer network layer and first layer network interface) message and handled to receive message and send, then due to The object-c codes that IOS systems use are more closed, can make journey in the network data distribution procedure of long connection The development process of sequence is more inefficient.
Invention content
In view of the deficiencies in the prior art, the purpose of the present invention is to provide long connection networks in a kind of IOS systems Data distribution and processing method and system solve the defect of the prior art.
The present invention is by writing and handling the Web vector graphic C Plus Plus for growing connection, and C++ codes offset when receiving message Breath is decrypted, and C++ codes to message to carry out packing processing when sending message, and is sent using socket.By making Write the characteristic that cross-system platform can be provided with C++ codes, can use such as Android, Windows, linux, In the system platforms such as IOS.Simultaneously using C++ codes can also be more efficient processing code.Usually all particularly with internet message It is encrypted, so then can efficiently decrypt encryption using C++ codes.C++ is again decoded message after having decrypted message Go out each field, then the field of decryption is pushed in IOS application layer codes.
To achieve the above objectives, the technical solution adopted by the present invention is that:
Long connection network data distribution and processing method in a kind of IOS systems of present invention offer, in client kimonos The network data distribution and processing of long connection are carried out between business device, which is characterized in that include the following steps:
The transmitting-receiving of the network data of long connection is carried out using the network interface layer of C++ written in code IOS system clients;
The network data received is decrypted and is unpacked;
The network data that C++ layer networks receive is transmitted to the object-c code layers of application layer;
Network data is pushed to by object-c code layers in the application layer of IOS.
Long connection network data distribution and processing method, can also have such spy in IOS systems provided by the invention Sign, the transmitting-receiving that network interface layer carries out the network data of long connection includes following procedure:
Network socket is created between reception and the client and server of distribution network data,
The IP address and port numbers of network socket are set,
Client is attached with server,
Network data is sended and received using thread function.
Long connection network data distribution and processing method, can also have such spy in IOS systems provided by the invention Sign, api function pthread_create that the thread function is carried by IOS systems are created.
Long connection network data distribution and processing method, can also have such spy in IOS systems provided by the invention Sign, the step of thread function sends and receivees network data include:
The event of network socket is monitored,
The case where according to monitoring, judges that current network socket is readable state or can using seletct functions Write state,
When being judged as readable state, the network data that server is sent is received by recv functions,
When be judged as can write state when, network data is sent to server by send functions.
Long connection network data distribution and processing method, can also have such spy in IOS systems provided by the invention Sign, decryption and the detailed process unpacked are:
It is decrypted using enciphering and deciphering algorithm TEA,
Parsing operation is carried out after the completion of decryption, parses the corresponding type of message of the network data and the information content.
Long connection network data distribution and processing method, can also have such spy in IOS systems provided by the invention Sign:
When the content of message when server mistake, then network socket can carry out network reconnection;
When the content of message is other content, then answering for IOS is pushed to via the object-c code layers of application layer With in layer.
Long connection network data distribution and processing method, can also have such spy in IOS systems provided by the invention Sign:
The process that the network data that C++ layer networks receive is transmitted to the object-c code layers of application layer is by IOS Included call back function callback and the Push function of system is realized.
Long connection network data distribution and processing method, can also have such spy in IOS systems provided by the invention Sign:After network data is pushed to the application layer of IOS, application layer is distributed to different modules to handle according to the type of information.
Long connection network data distribution and processing method, can also have such spy in IOS systems provided by the invention Sign:
The client is network direct broadcasting client, and the server is network direct broadcasting server,
The application layer is network direct broadcasting platform,
When type of message is barrage type, the barrage display area which can be put into application layer by application layer is shown Show,
When type of message is present type, the present display area which can be put into application layer by application layer is shown Show,
When type of message is even wheat type, application layer can the setting of company of pop-up wheat, start company's wheat function.
The present invention also provides long connection network data distribution and processing systems in a kind of IOS systems, which is characterized in that packet It includes:
Network Interface Module, the network interface for building C++ codes carry out the transmitting-receiving of the network data of long connection;
Decryption unpacks module, and the network data received is decrypted and is unpacked;
Transfer module, the network data for receiving C++ layer networks are transmitted to the object-c code layers of application layer;
Pushing module, for network data to be pushed to by object-c code layers in the application layer of IOS.
The function and effect of the present invention is:According to long connection network data distribution in IOS systems provided by the invention and Processing method, because having steps of:
The transmitting-receiving of the network data of long connection is carried out using the network interface layer of C++ written in code IOS system clients;It is right The network data received is decrypted and unpacks;The network data that C++ layer networks receive is transmitted to application layer Object-c code layers;Network data is pushed to by object-c code layers in the application layer of IOS, that is to say, that application layer It only needs to handle the distribution of type of message and different type of messages is handled, and for received message, decryption message is then It is all realized by C++ bottom codes, the long and is exactly the improved efficiency so that the development process of IOS application layers becomes simple.Separately On the one hand, write the characteristic that cross-system platform can be provided using C++ codes, can use such as Android, In the system platforms such as Windows, linux, IOS.
Description of the drawings
Fig. 1 is that the step of length connects network data distribution and processing method in the IOS systems in the embodiment of the present invention is shown It is intended to;
Fig. 2 is the transceiving step schematic diagram for the network data that network interface layer carries out long connection in the embodiment of the present invention;
Fig. 3 is the step schematic diagram that the embodiment of the present invention thread function sends and receivees network data;And
Fig. 4 is long connection network data distribution and the structural representation of processing system in IOS systems in the embodiment of the present invention Figure.
Specific implementation mode
It is real below in order to make the technical means, the creative features, the aims and the efficiencies achieved by the present invention be easy to understand Apply example combination attached drawing to the composition of long connection network data distribution and processing method and system in the IOS systems of the present invention, structure, Connection relation, specific workflow and operation principle, effect and effect, which are specifically described, to be specifically addressed.
Below in the network direct broadcasting in background technology, direct broadcast server carries out long connection by network communication to client (long connection, multiple data packets can be continuously transmitted at one in connection by referring to, during connecting holding, if sent out without data packet Send, both sides needed to send out link detecting packet) it is described in detail the case where sending network data.
Embodiment 1
Fig. 1 is that the step of length connects network data distribution and processing method in the IOS systems in the embodiment of the present invention is shown It is intended to.
As shown in Figure 1, the network data distribution of the present embodiment and processing method have step S1-S5.
Step S1 carries out the network data of long connection using the network interface layer of C++ written in code IOS system clients Transmitting-receiving.
Fig. 2 is the transceiving step schematic diagram for the network data that network interface layer carries out long connection in the embodiment of the present invention.
The present invention be directed to mobile intelligent terminal or desktop computer IOS application programs, in order in the third of network communication Layer transport layer, second layer network layer and first layer network interface carry out the network communication of long connection, need to open using C++ codes The interface of hairnet network transceiving data, i.e., in first layer network interface using C++ code developments data-interface come in different operations It is operated between system, can both make it possible to and executed in different system platforms, while its execution can also be improved Efficiency.The transmitting-receiving for the network data that specific network interface layer carries out long connection includes the following steps:
Step S1-1 creates network socket between reception and the client and server of distribution network data.
Long linked network is carried out by writing socket programs, so firstly the need of a web socket is created socket.The specific then api function int sockfd that are provided by IOS systems:
Int sockfd=socket (AF_INET, SOCK_STREAM, 0);
To be created, wherein
Socket then indicates to create the web socket socket of a streaming.
First parameter AF_INET indicates IPv4Internet agreements.
Second parameter SOCK_STREAM indicates Tcp connections, provide serializing, reliably, the byte that is bi-directionally connected Stream.
It is 0 that third parameter, which is then filled out,.
Step S1-2, the IP address and port numbers of setting network socket.
After setting socket, client needs the IP address and port numbers of inserting server before Connection Service device It is linked, only specifies IP address and corresponding port numbers, specified server program can be linked to.
The present embodiment is to store the addresses ip and the port numbers of setting, network by defining the structure of a network address The structure of address is:
struct sockaddr_in serveraddr;
Serveraddr.sin_family=AF_INET;
Serveraddr.sin_port=port;
Serveraddr.sin_addr.s_addr=ip;
The port and ip wherein inserted is exactly the addresses ip and the port numbers of server.
Step S1-3, client are attached with server.
Start linked server.When creating socket word network socket, after filling in server address, then can go to link Server.IOS systems provide a corresponding function connect and carry out linked server.Function is as follows:
int connect(int sockfd,const struct sockaddr*addr,socklen_t addrlen);
Using the function, the client of TCP networks is connect by connect functions with server-side, is communicated, wherein Sockfd is that the network socket word network socket, Addr that create before are the IP address of the server created before, Addrlen It is the length of IP address data.
Input order in this way:
connect(sockfd,&serveraddr,sizeof(serveraddr));
Connect functions are run, client begins to linked server.
Step S1-4 sends and receivees network data using thread function.
Server message and transmission server message are received to write program using Socket, which is that an IO is (defeated Enter output) it operates, so it will produce blocking operation, in order to which program is capable of the execution of flow, then need establishment one independent Thread function carries out transmitting-receiving operation to internet message, the corresponding api function that is provided using IOS systems in the present embodiment Pthread_create creates thread function.
The function that thread creation is carried out using api function pthread_create is as follows:
int pthread_create(pthread_t*tidp,const pthread_attr_t*restrict_attr, void*(*start_rtn)(void*),void*restrict arg);
Wherein, first parameter pthread_t*tidp is the pointer for being directed toward thread identifier, second parameter const Pthread_attr_t*restrict_attr is for thread attribute, third parameter void* (* start_rtn) is arranged (void*) be thread operation function initial address, the last one parameter void*restrict arg are active thread functions Parameter.
Fig. 3 is the step schematic diagram that the embodiment of the present invention thread function sends and receivees network data.
So important is then thread function, and the present embodiment defines a SocketRun as thread function, the thread Function sends and receivees the step of network data and includes:
Step S1-4-1, SocketRun monitor the event of network socket as thread function, by life below Code is enabled to realize:
Thread function can then write while cycles the event of socket is monitored and be handled.
Step S1-4-2, according to monitor the case where, judge that current network socket is readable using seletct functions State still can write state.
By to socket, using select functions, judge receiving the message of server by current sokcet, be in can Read states still can write state, select functions are:
Ret=Select (socket);
Judge that current socket socket is can to read by select functions, still can write.
Step S1-4-3 receives the network data that server is sent when being judged as readable state by recv functions.
If it is determined that readable state, then illustrate to have received the message that server is sent to client, just pass through recv letters It counts to receive the message of server:
recv(socket,(char*)buf,len,0);
Wherein first parameter socket is the socket created before, and second parameter (char*) buf is that storage receives The message of the server arrived, third parameter len are the length of the data received, and it is 0 that the 4th parameter, which does not use,.
Step S1-4-4, when be judged as can write state when, network data is sent to server by send functions.
If it is determined that can write state, then illustrate that current socket can send data to server, just pass through system The send functions of offer send a message to server:
send(socket,(char*)buf,(size_t)(len),0);
Wherein first parameter socket is the socket created before, and second parameter (char*) buf is to have write The data for needing to be sent to server are entered, third parameter (size_t) (len) is the length of data in buf, the 4th ginseng It is 0 that number, which does not use,.
Thread function can then write while cycles, this cycle then can constantly handle the message data for receiving server, and And server is sent data to, so far, the processing of client network data transmit-receive is achieved that by the step.
Step S2 is decrypted and unpacks to the network data received.
Server sends a message to client, for safety, needs that message is encrypted.And client exists After the message for receiving server, need that operation is decrypted to message, while after the completion of decryption, the message of outbound message can be decrypted Type, to carry out the transmission of message by type and handle in next step.
Decryption and the detailed process unpacked are:
First, it is decrypted using enciphering and deciphering algorithm TEA.
The TEA enciphering and deciphering algorithm functions of lightweight are used for internet message encryption and decryption the present embodiment:
TEA.Decrypt(encryptbuf,len);
Wherein TEA.Decrypt is the interface function of TEA ciphertext datas, and parameter encryptbuf is the net that server is sent Network data, that is, encrypted data are wanted, parameter len is the length of data.
Then, parsing operation is carried out after the completion of decryption, parses the corresponding type of message of the network data and information Content.
After the completion of decryption, de-packaging operation is carried out to message, so as to parse the type of outbound message, this message is assorted , use unpacking function unpack:
Type=unpack (encryptbuf, len);
Wherein, unpack is corresponding unpacking function, wherein the parameter encryptbuf inputted is then the clothes decrypted before Business device message, parameter len is then the length for the server message decrypted before.By type it is known that current network disappears What breath is, specifically which classification.
So far, the process that the message of server is decrypted and is parsed is achieved that by the step.
The network data that C++ layer networks receive is transmitted to the object-c code layers of application layer by step S3.
In order to be preferably managed to the distribution of message and processing, the present embodiment is write one at C++ layers and abstract is connect Mouthful, it is supplied to application layer object-c, abstraction interface then to define the interface and parameter type of PUSH message, by C++ layer networks The process that the network data received is transmitted to the object-c code layers of application layer is the call back function carried by IOS systems What callback and Push functions were realized.
Call back function callback is specifically named as ICallback, specific code is as follows:
An empty ICallback is write, to prevent RAM leakage, wherein interface name is a class, ICallback。
Define Push functions:OnPush, Function Format are:
Virtual void OnPush (const char*type, const char*message)=0;
}
A pure virtual function OnPush is defined, is the interface function that the present embodiment is write, wherein parameter const Char*type indicates that the type of message, parameter const char*message indicate message.Re-define an interface function SetCallback is used to be arranged the specific example of this interface to object-c:
void SetCallback(ICallback*callback);
This interface function is used to the specific example of application layer setting ICallback.
And for C++ layers of bottom, for realizing that SetCallback functions store the mesh of the interface instance of application layer setting 's.
For C++ layers, the setting example that a global ICallback pointer is used to store application program is defined:
ICallback*g_callback=NULL;
Then it is configured in SetCallback.
For the data of network decrypting server and the data of resolution server write before, it is being parsed Afterwards, then this call back function callback can be called to be delivered in the code of the object-c of application layer, specific code It is as follows:
g_callback->OnPush(type,encryptbuf);
Wherein OnPush is then the interface write.
Wherein type is then the type of message.
Wherein encryptbuf be then before the network data that parses after server decryption.
To by calling the data transfer after the OnPush functions network analysis that receives C++ layers to application layer Object-c code layers.
So far, it is achieved that by the step and the net that corresponding interface code receives bottom is write by using C++ Network message data is transmitted in the object-c code layers of application layer.
Network data is pushed to by object-c code layers in the application layer of IOS by step S4.
After network data is pushed to the application layer of IOS, application layer according to the type of information be distributed to different modules come Processing.
For application layer code, the code function for realizing corresponding interface layer is needed, that is to say and write call back function The subclass of ICallback classes, and realize that therein deposit needs Push function OnPush, to receive network data in c++ code layers Afterwards, can be by the OnPush interface codes of calling application layer, it will be in network data transmitting to application layer.
The code for writing the subclass of call back function ICallback classes is:
class CNetCallback public:ICallback
Wherein, CNetCallback is inherited from ICallback, and code is:
{
public:
Interface void OnPush (const char*type, const char*message)
Wherein CNetCallback classes must satisfy the function of realizing OnPush interfaces, in this way in bottom C++ code calls When, what is actually called is then the OnPush interfaces for this CNetCallback class that application layer is write, in this way, being achieved that C+ + data transfer to the object-c code layers of IOS application layers in.
In this OnPush interface function, application layer then can carry out the distribution of message according to the type type of message, I.e. application layer is distributed to different modules to handle according to the type of information.
In the present embodiment, the client is network direct broadcasting client, and the server is network direct broadcasting server, institute In the case of application layer is stated as network direct broadcasting platform, the code write is:If (type==" danmu ")
If type of message is " danmu " barrage message, the barrage display area that barrage is put into application layer is shown Show.
Else if (type==" gift ")
If type of message is " gift " present message, present is shown to the present region of application layer.
Else if (type==" voicelink ")
If type of message is " voicelink " even wheat message, application layer pop-up even wheat setting starts even wheat function.
}
Particularly as being:
When type of message is barrage type, the barrage display area which can be put into application layer by application layer is shown Show,
When type of message is present type, the present display area which can be put into application layer by application layer is shown Show,
When type of message is even wheat type, application layer can the setting of company of pop-up wheat, start company's wheat function.
By above process, after network data is pushed to the application layer of IOS, application layer is distributed according to the type of information It is handled to different modules, in this way, application layer only needs to write the code of the distribution realization of type of message and application program is wanted The respective code of the type of message of processing, and received message, decryption message are then all realized by C++ bottom codes, total As a result it is exactly that the development process of IOS application layers is made to become simple, improved efficiency, and without concern third layer transport layer, second The realization process of layer network layer so that the written in code of the client of IOS systems and the network data distribution procedure of server becomes Simply, without going to consider the problems of how network socket etc. realize in network layer and transport layer.
As a kind of optimization to the present embodiment, in step s 2, when C++ layer networks receive the message of server and right After message has carried out decryption and de-packaging operation, in order to cope with situations such as server being likely to occur does not connect or breaks, meeting There are a judgment step, the content of the network data to decrypting judges:
When the content of message is server mistake, then network socket can carry out network reconnection;
When the content of message is other content, then answering for IOS is pushed to via the object-c code layers of application layer With in layer.
That is, if message content is " server mistake ", the Socket of C++ can carry out network reconnection, otherwise If it is other contents, the code that can be pushed to the object-c of application layer goes to handle and show, e.g. barrage message, The barrage display area that barrage is just put into application layer is shown.
Embodiment 2
Fig. 4 is long connection network data distribution and the structural representation of processing system in IOS systems in the embodiment of the present invention Figure.
Long connection network data distribution and processing system combination attached drawing in IOS systems provided in this embodiment are carried out below It is described in detail.
As shown in figure 4, long connection network data distribution and processing system 100 include Network Interface Module in IOS systems 101, decryption unpacks module 102, transfer module 103, pushing module 104.
Network Interface Module 101, the network interface for building C++ codes carry out the transmitting-receiving of the network data of long connection.
Decryption unpacks module 102, and the network data received is decrypted and is unpacked.
Transfer module 103, the network data for receiving C++ layer networks are transmitted to the object-c codes of application layer Layer.
Pushing module 104, for network data to be pushed to by object-c code layers in the application layer of IOS.
Specifically, Network Interface Module 101 has
Socket creating units 1011, for creating net between reception and the client and server of distribution network data Network socket.
Setting unit 1012, IP address and port numbers for network socket to be arranged.
Connection unit 1013, is attached for client and server.
Unit 1014 is sended and received, for sending and receiving network data using thread function.
Specifically, sending and receiving unit 1014 and including:
First subelement, for being monitored the event of network socket by SocketRun thread functions;
Second subelement judges that current network socket is using seletct functions the case where being used for according to monitoring Readable state still can write state
Third subelement, for being handled according to state:
When being judged as readable state, the network data that server is sent is received by recv functions
When be judged as can write state when, network data is sent to server by send functions.
Embodiment 3
The present embodiment also provides a kind of electronic device, including memory and processor, is stored in processor on memory The computer program of upper operation, it is characterised in that:Processor realizes the following method when executing computer program:
Step S1 carries out the network data of long connection using the network interface layer of C++ written in code IOS system clients Transmitting-receiving;
Step S2 is decrypted and unpacks to the network data received;
The network data that C++ layer networks receive is transmitted to the object-c code layers of application layer by step S3;
Network data is pushed to by object-c code layers in the application layer of IOS by step S4.
Wherein, the transmitting-receiving that network interface layer carries out the network data of long connection includes following procedure:
Step S1-1 creates network socket between reception and the client and server of distribution network data;
Step S1-2, the IP address and port numbers of setting network socket;
Step S1-3, client are attached with server;
Step S1-4 sends and receivees network data using thread function.
And in step S1-4, the step of thread function sends and receivees network data, includes
Step S1-4-1 monitors the event of network socket,
Step S1-4-2, according to monitor the case where, judge that current network socket is readable using seletct functions State still can write state,
Step S1-4-2 receives the network data that server is sent when being judged as readable state by recv functions,
Step S1-4-2, when be judged as can write state when, network data is sent to server by send functions.
Embodiment 4
Storage medium provided in this embodiment is described in detail below.
A kind of storage medium is stored with computer program on the storage medium, and the computer program is executed by processor Shi Shixian the following method:
Step S1 carries out the network data of long connection using the network interface layer of C++ written in code IOS system clients Transmitting-receiving;
Step S2 is decrypted and unpacks to the network data received;
The network data that C++ layer networks receive is transmitted to the object-c code layers of application layer by step S3;
Network data is pushed to by object-c code layers in the application layer of IOS by step S4.
Wherein, the transmitting-receiving that network interface layer carries out the network data of long connection includes following procedure:
Step S1-1 creates network socket between reception and the client and server of distribution network data;
Step S1-2, the IP address and port numbers of setting network socket;
Step S1-3, client are attached with server;
Step S1-4 sends and receivees network data using thread function.
And in step S1-4, the step of thread function sends and receivees network data, includes
Step S1-4-1 monitors the event of network socket,
Step S1-4-2, according to monitor the case where, judge that current network socket is readable using seletct functions State still can write state,
Step S1-4-3 receives the network data that server is sent when being judged as readable state by recv functions,
Step S1-4-4, when be judged as can write state when, network data is sent to server by send functions.
The effect of the present embodiment and effect:According to long connection network data distribution in IOS systems provided in this embodiment and Processing method, because having steps of:
The transmitting-receiving of the network data of long connection is carried out using the network interface layer of C++ written in code IOS system clients;It is right The network data received is decrypted and unpacks;The network data that C++ layer networks receive is transmitted to application layer Object-c code layers;Network data is pushed to by object-c code layers in the application layer of IOS, that is to say, that application layer It only needs to handle the distribution of type of message and different type of messages is handled, and for received message, decryption message is then It is all realized by C++ bottom codes, the long and is exactly the improved efficiency so that the development process of IOS application layers becomes simple.Separately On the one hand, write the characteristic that cross-system platform can be provided using C++ codes, can use such as Android, In the system platforms such as Windows, linux, IOS.
Because in step s 2, when C++ layer networks receive the message of server and message decrypt and unpacked After operation, in order to cope with situations such as server being likely to occur does not connect or breaks, there can be a judgment step, to solution It is close to the content of network data judged and handled, in this way when message content is " server mistake ", then the Socket of C++ Can carry out network reconnection, else if for other contents, then can be pushed to the object-c of application layer code go processing and Displaying, the process judged in advance by this can ensure in the failure for occurring breaking or not connecting, and carry out corresponding Processing.
Further, the event of network socket is monitored using thread function, and according to monitor the case where, use Seletct functions come judge current network socket be readable state or can write state, in this way can be in different read-writes The corresponding arrangement of state sends and receives operation, has specific aim, be not in read-write state and reception transmission state not Match.
It should be understood by those skilled in the art that, the embodiment of the present invention can be provided as method, system or computer program Product.Therefore, complete hardware embodiment, complete software embodiment or reality combining software and hardware aspects can be used in the present invention Apply the form of example.Moreover, the present invention can be used in one or more wherein include computer usable program code computer The shape for the computer program product implemented in usable storage medium (including but not limited to magnetic disk storage and optical memory etc.) Formula.
The present invention be with reference to according to the method for the embodiment of the present invention, the flow of equipment (system) and computer program product Figure and/or block diagram describe.It should be understood that can be realized by computer program instructions every first-class in flowchart and/or the block diagram The combination of flow and/or box in journey and/or box and flowchart and/or the block diagram.These computer programs can be provided Instruct the processor of all-purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices to produce A raw machine so that the instruction executed by computer or the processor of other programmable data processing devices is generated for real The device for the function of being specified in present one flow of flow chart or one box of multiple flows and/or block diagram or multiple boxes.
These computer program instructions, which may also be stored in, can guide computer or other programmable data processing devices with spy Determine in the computer-readable memory that mode works so that instruction generation stored in the computer readable memory includes referring to Enable the manufacture of device, the command device realize in one flow of flow chart or multiple flows and/or one box of block diagram or The function of being specified in multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device so that count Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, in computer or The instruction executed on other programmable devices is provided for realizing in one flow of flow chart or multiple flows and/or block diagram one The step of function of being specified in a box or multiple boxes.
Obviously, various changes and modifications can be made to the invention without departing from essence of the invention by those skilled in the art God and range.In this way, if these modifications and changes of the present invention belongs to the range of the claims in the present invention and its equivalent technologies Within, then the present invention is also intended to include these modifications and variations.
The present invention is not limited to the above-described embodiments, for those skilled in the art, is not departing from Under the premise of the principle of the invention, several improvements and modifications can also be made, these improvements and modifications are also considered as the protection of the present invention Within the scope of.The content not being described in detail in this specification belongs to the prior art well known to professional and technical personnel in the field.

Claims (10)

  1. Long connection network data distribution and processing method in 1.IOS systems, for carrying out long company between clients and servers The network data distribution and processing connect, which is characterized in that include the following steps:
    The transmitting-receiving of the network data of long connection is carried out using the network interface layer of C++ written in code IOS system clients;
    The network data received is decrypted and is unpacked;
    The network data that C++ layer networks receive is transmitted to the object-c code layers of application layer;
    Network data is pushed to by object-c code layers in the application layer of IOS.
  2. 2. long connection network data distribution and processing method in IOS systems according to claim 1, it is characterised in that:
    Wherein, the transmitting-receiving that network interface layer carries out the network data of long connection includes following procedure
    Network socket is created between reception and the client and server of distribution network data,
    The IP address and port numbers of network socket are set,
    Client is attached with server,
    Network data is sended and received using thread function.
  3. 3. long connection network data distribution and processing method in IOS systems according to claim 2, it is characterised in that:
    Wherein, the thread function is carried by IOS systems api function pthread_create is created.
  4. 4. long connection network data distribution and processing method in IOS systems according to claim 3, it is characterised in that:
    Wherein, the step of thread function sends and receivees network data include
    The event of network socket is monitored,
    The case where according to monitoring, judge that current network socket is readable state or writeable shape using seletct functions State,
    When being judged as readable state, the network data that server is sent is received by recv functions,
    When be judged as can write state when, network data is sent to server by send functions.
  5. 5. long connection network data distribution and processing method in IOS systems according to claim 1, it is characterised in that:
    Wherein, it decrypts and the detailed process of unpacking is
    It is decrypted using enciphering and deciphering algorithm TEA,
    Parsing operation is carried out after the completion of decryption, parses the corresponding type of message of the network data and the information content.
  6. 6. long connection network data distribution and processing method in IOS systems according to claim 5, it is characterised in that:
    Wherein,
    When the content of message when server mistake, then network socket can carry out network reconnection;
    When the content of message is other content, then the application layer of IOS is pushed to via the object-c code layers of application layer In.
  7. 7. long connection network data distribution and processing method in IOS systems according to claim 1, it is characterised in that:
    The process that the network data that C++ layer networks receive is transmitted to the object-c code layers of application layer is by IOS systems What included call back function callback and Push function was realized.
  8. 8. long connection network data distribution and processing method in IOS systems according to claim 1, it is characterised in that:
    After network data is pushed to the application layer of IOS, application layer is distributed to different modules to handle according to the type of information.
  9. 9. long connection network data distribution and processing method in IOS systems according to claim 8, it is characterised in that:
    The client is network direct broadcasting client, and the server is network direct broadcasting server,
    The application layer is network direct broadcasting platform,
    When type of message is barrage type, the barrage display area which can be put into application layer by application layer is shown,
    When type of message is present type, the present display area which can be put into application layer by application layer is shown,
    When type of message is even wheat type, application layer can the setting of company of pop-up wheat, start company's wheat function.
  10. 10. long connection network data distribution and processing system in a kind of IOS systems, which is characterized in that including:
    Network Interface Module, the network interface for building C++ codes carry out the transmitting-receiving of the network data of long connection;
    Decryption unpacks module, and the network data received is decrypted and is unpacked;
    Transfer module, the network data for receiving C++ layer networks are transmitted to the object-c code layers of application layer;
    Pushing module, for network data to be pushed to by object-c code layers in the application layer of IOS.
CN201810745083.5A 2018-07-09 2018-07-09 Long connection network data distribution and processing method and system in IOS system Active CN108696537B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810745083.5A CN108696537B (en) 2018-07-09 2018-07-09 Long connection network data distribution and processing method and system in IOS system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810745083.5A CN108696537B (en) 2018-07-09 2018-07-09 Long connection network data distribution and processing method and system in IOS system

Publications (2)

Publication Number Publication Date
CN108696537A true CN108696537A (en) 2018-10-23
CN108696537B CN108696537B (en) 2020-10-16

Family

ID=63851540

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810745083.5A Active CN108696537B (en) 2018-07-09 2018-07-09 Long connection network data distribution and processing method and system in IOS system

Country Status (1)

Country Link
CN (1) CN108696537B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109842623A (en) * 2019-01-30 2019-06-04 常州玖玖盾数据科技有限公司 Big data distribution method for industry control safety database auditing system
CN112671760A (en) * 2020-12-22 2021-04-16 平安普惠企业管理有限公司 Socket-based client cross-platform network communication method and related equipment thereof

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130086141A1 (en) * 2011-09-29 2013-04-04 Anil Saldhana Systems and methods for security token management service hosted in application server
CN104244290A (en) * 2014-09-27 2014-12-24 昆明钢铁集团有限责任公司 Time-controllable IOS (internet work operating system) intranet reachability detecting system and method
CN105992026A (en) * 2015-02-11 2016-10-05 无锡掌睿星软件技术有限公司 Method and device for displaying barrage comment information
CN107612744A (en) * 2017-10-12 2018-01-19 连云港杰瑞电子有限公司 A kind of intelligent transportation equipment operational system based on mobile platform
CN108173946A (en) * 2017-12-29 2018-06-15 明博教育科技股份有限公司 A kind of method, system and correlation technique for realizing classroom real-time interactive

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130086141A1 (en) * 2011-09-29 2013-04-04 Anil Saldhana Systems and methods for security token management service hosted in application server
CN104244290A (en) * 2014-09-27 2014-12-24 昆明钢铁集团有限责任公司 Time-controllable IOS (internet work operating system) intranet reachability detecting system and method
CN105992026A (en) * 2015-02-11 2016-10-05 无锡掌睿星软件技术有限公司 Method and device for displaying barrage comment information
CN107612744A (en) * 2017-10-12 2018-01-19 连云港杰瑞电子有限公司 A kind of intelligent transportation equipment operational system based on mobile platform
CN108173946A (en) * 2017-12-29 2018-06-15 明博教育科技股份有限公司 A kind of method, system and correlation technique for realizing classroom real-time interactive

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109842623A (en) * 2019-01-30 2019-06-04 常州玖玖盾数据科技有限公司 Big data distribution method for industry control safety database auditing system
CN112671760A (en) * 2020-12-22 2021-04-16 平安普惠企业管理有限公司 Socket-based client cross-platform network communication method and related equipment thereof

Also Published As

Publication number Publication date
CN108696537B (en) 2020-10-16

Similar Documents

Publication Publication Date Title
WO2023087938A1 (en) Data processing method, programmable network card device, physical server, and storage medium
CN106559251B (en) A kind of Compilation Method and corresponding interface, component and system based on YANG model
CN101902473B (en) Method for synchronously updating data based on grid GIS (Geographic Information System)
CN101227343B (en) Method and device for testing TCPv6 and UDPv6
CN102497427B (en) Method and device for realizing data acquisition services of renewable energy source monitoring system
CN102790776A (en) Heartbeat connection normalizing processing method, terminal, server and communication system
CN105939284B (en) The matching process and device of message control strategy
EP2429150A1 (en) Apparatus, web service component and method based on web service
CN104394544A (en) Automatic radio frequency test method for WiFi (Wireless Fidelity) product
CN108696537A (en) Long connection network data distribution and processing method and system in IOS systems
CN110187986A (en) A kind of command management method, system, device and computer readable storage medium
WO2023087766A1 (en) Dual-system communication method and apparatus, and electronic device and computer-readable storage medium
CN105190530A (en) Transmitting hardware-rendered graphical data
CN109543452A (en) Data transmission method, device, electronic equipment and computer readable storage medium
CN104836831B (en) A kind of object method of servicing for Internet of Things
CN103220648A (en) Information interaction method, information interaction system and advertisement interaction method based on short message
CN103309722A (en) Cloud computation system and application access method thereof
CN102868559A (en) Method and system for generating weblog data
CN103530342B (en) Method and device for sharing data
CN106488269A (en) System and method to television equipment control is realized based on third-party application platform
CN108353017B (en) Computing system and method for operating multiple gateways on a multi-gateway virtual machine
CN104820803A (en) Method of sharing data among corporation mobile applications
CN103118023B (en) A kind of method and system of the data of transmission specification in a network
CN107204896A (en) Handle method, device and the VTEP equipment of VXLAN messages
CN103825767B (en) The implementation method and bridge of service quality

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