CN104219231A - Multi-protocol communication framework and communication method based on Android system - Google Patents

Multi-protocol communication framework and communication method based on Android system Download PDF

Info

Publication number
CN104219231A
CN104219231A CN201410419975.8A CN201410419975A CN104219231A CN 104219231 A CN104219231 A CN 104219231A CN 201410419975 A CN201410419975 A CN 201410419975A CN 104219231 A CN104219231 A CN 104219231A
Authority
CN
China
Prior art keywords
nio
data
module
processing module
connection request
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.)
Pending
Application number
CN201410419975.8A
Other languages
Chinese (zh)
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.)
Huazhong University of Science and Technology
Original Assignee
Huazhong University of Science and Technology
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 Huazhong University of Science and Technology filed Critical Huazhong University of Science and Technology
Priority to CN201410419975.8A priority Critical patent/CN104219231A/en
Publication of CN104219231A publication Critical patent/CN104219231A/en
Pending legal-status Critical Current

Links

Landscapes

  • Communication Control (AREA)

Abstract

The invention provides to a multi-protocol communication framework and communication method based on an Android system and relates to the technical field of network communication of the Android system. The multi-protocol communication framework comprises an NIO thread pool module, an NIO network accessing module and an NIO data processing module which are connected sequentially. The NIO thread pool module establishes one NIO communication thread according to one received access request once; the NIO network accessing module establishes the corresponded accessing channel and data processing joint according to the type of each accessing request and transmits the data received by the data processing joint to the NIO data processing module; the NIO data processing module is used for processing the data transmitted by the NIO network accessing module. By the aid of the framework and method, multiple protocol concurrent requests can be supported, network communication can be implemented effectively and rapidly, and resource and time consumption is reduced.

Description

A kind of multi-protocol communication framework based on android system and the means of communication
Technical field
The present invention relates to the technical field of network communication of android system, is specifically a kind of multi-protocol communication framework based on android system and the means of communication.
Background technology
Android is the intelligent platform of a new generation, and increasing electric terminal uses Android as operating system, and the user of the electric terminal of android system is grown with each passing day.In recent years, (product such as mobile phone or panel computer), powerful network application and global IT enterprises all advantages such as power-assisted Android selected by its significant open, abundant hardware of taking of android system, become the leader of the tendency of the day.Increasing people brings into use with the products such as the mobile phone of android system or panel computer (market share of latest data display smart mobile phone is 88%).But the application technology that android system exchanges at multi-protocol information and tackles in high concurrent network request is not yet ripe, and particularly the communication of android system cannot carry out various protocols switching quickly and efficiently.
At present, the mode one to one of the existing multiple connection of already present android system communication many employings multiple threads.When there being 10000 connection requests, just may needing 10000 threads and processing, resource consumption is very big, and can produce obstruction.And a large amount of threads will be brought to carry out contextual processing continually once block generation, thus make time loss excessive.In addition, in existing android system communication, multi-protocols concurrent request does not have systematic combining, and cannot realize the switching between various protocols rapidly, makes the processing speed of communication connection request slower.
Summary of the invention
For the defect existed in prior art, the object of the present invention is to provide a kind of multi-protocol communication framework based on android system and the means of communication, support the concurrent request of various protocols, efficiently, quickly can realize network communication, reduce the consumption of resource and time.
For reaching above object, the invention provides a kind of multi-protocol communication framework based on android system, comprising: the NIO thread pool module, NIO network connecting module and the NIO data processing module that connect successively.Wherein, described NIO thread pool module is according at least one connection request received at every turn, and create a NIO communication thread, each connection request is sent to NIO network connecting module by described NIO communication thread; Described NIO network connecting module creates corresponding interface channel and corresponding data-processing interface according to the type of each connection request, and the data received by data-processing interface send NIO data processing module to; Described NIO data processing module is used for processing the data that NIO network connecting module transmits.
On the basis of technique scheme, the number scope of the connection request that described NIO thread pool module receives at every turn is 1 ~ 5.
On the basis of technique scheme, the type of described connection request comprises TCP connection, UDP connects and is connected with HTTP.
On the basis of technique scheme, described NIO data processing module comprises the HTTP data processing module of the tcp data processing module of process TCP connection data, the UDP message processing module of process UDP connection data and process HTTP connection data.
The present invention also provides a kind of multi-protocol communication method based on android system, comprises the steps:
S1: initialization NIO thread pool module, and receive connection request, and NIO thread pool module receives at least one connection request at every turn.
After S2:NIO thread pool module receives at least one connection request described at every turn, just create a NIO communication thread, each connection request is sent to NIO network connecting module by described NIO communication thread.
S3:NIO network connecting module, according to the type of each connection request, creates corresponding interface channel and corresponding data-processing interface.
S4:NIO communication thread is monitored each data-processing interface, has judged whether that data arrive, has if so, then entered S5, if not, then continues to monitor.
S5:NIO communication thread notice NIO network connecting module, and data are submitted to NIO network connecting module.
S6:NIO network connecting module after receiving the data, transfers to NIO data processing module to process.
On the basis of technique scheme, in step S1, the type of described connection request comprises TCP connection, UDP connects and is connected with HTTP.
On the basis of technique scheme, in step S3, NIO network connecting module, creates socket passage and corresponding NIO processor interface according to the connection request that TCP connects; Datagram passage and corresponding NIO processor interface is created according to the connection request that UDP connects; Socket passage and corresponding NIO processor interface is created according to the connection request that HTTP connects.
On the basis of technique scheme, described NIO data processing module comprises tcp data processing module, UDP message processing module and HTTP data processing module.In step S6, NIO network connecting module after receiving the data, by judging according to the interface channel of data to belong to that TCP connects, UDP connects, HTTP connect in any, and transfer to corresponding tcp data processing module, UDP message processing module, HTTP data processing module in NIO data processing module to process.
On the basis of technique scheme, in described step S6, when NIO data processing module processes, if there is the incomplete situation of data receiver, show to connect disconnection, then feedback needs the message reconnected to NIO network connecting module; Do not receive the situation of data if occur, show to connect time-out, then point out NIO network connecting module to check interface channel and corresponding data-processing interface, and reconnect; If there is the situation of the error in data received, then notify that NIO network connecting module reassigns interface channel and corresponding data-processing interface.
Beneficial effect of the present invention is:
1, present invention employs the design of thread pool module, define the means of communication of NIO (Non-blocking I/O, unblock communication mode).The method makes the number processing Thread Count and the connection request connected not have man-to-man contact, and that is process 10000 connection requests, NIO mode does not need 10000 threads, can process with 2000 or less thread.Like this, just avoid a large amount of threads and carry out contextual processing continually, efficiently, quickly can realize network communication, reduce resource and the consumption of time.
2, the present invention's combining multi-protocols concurrent request system, support TCP (Transmission Control Protocol simultaneously, transmission control protocol), UDP (User Data Protocol, User Datagram Protoco (UDP)) and HTTP (Hypertext Transfer Protocol, HTTP), can switch between multi-protocols quickly and easily, significantly improve system works efficiency.
3, NIO data processing module of the present invention can also realize connecting the process disconnecting, connect the faults such as time-out and Data reception errors, improves the fault-tolerance of system, ensure that the stability of system cloud gray model.
Accompanying drawing explanation
Fig. 1 is the structured flowchart of the multi-protocol communication framework that the present invention is based on android system;
Fig. 2 is the flow chart of the multi-protocol communication method that the present invention is based on android system.
Embodiment
Below in conjunction with accompanying drawing, embodiments of the invention are described in further detail.
As shown in Figure 1, the invention provides a kind of multi-protocol communication framework based on android system, comprise the NIO thread pool module, NIO network connecting module and the NIO data processing module that connect successively.
Wherein, described NIO thread pool module is according at least one connection request received at every turn, and create a NIO communication thread, each connection request is sent to NIO network connecting module by described NIO communication thread.The design of NIO thread pool module, define unblock communication mode, the number of NIO communication thread that process is connected and the number of connection request are without the need to man-to-man contact, avoid a large amount of threads and carry out contextual processing continually, efficiently, quickly network communication be can realize, resource and the consumption of time reduced.And, the number scope of the connection request that NIO thread pool module receives at every turn is 1 ~ 5, the type of connection request comprises TCP connection, UDP connects and is connected with HTTP, Transmission Control Protocol, udp protocol and http protocol can be supported simultaneously, can switch between multi-protocols quickly and easily, significantly improve system works efficiency.
Described NIO network connecting module creates corresponding interface channel and corresponding data-processing interface according to the type of each connection request, and the data received by data-processing interface send NIO data processing module to.
Described NIO data processing module is used for processing the data that NIO network connecting module transmits.Wherein, described NIO data processing module comprises the HTTP data processing module of the tcp data processing module of process TCP connection data, the UDP message processing module of process UDP connection data and process HTTP connection data.
As shown in Figure 2, a kind of multi-protocol communication method based on android system, comprises the steps:
S1: initialization NIO thread pool module, and receive connection request, and NIO thread pool module receives at least one connection request at every turn.Wherein, the type of connection request comprises TCP connection, UDP connection is connected with HTTP.
After S2:NIO thread pool module receives at least one connection request described at every turn, just create a NIO communication thread, each connection request is sent to NIO network connecting module by described NIO communication thread;
S3:NIO network connecting module, according to the type of each connection request, creates corresponding interface channel and corresponding data-processing interface.Specifically, the connection request connected according to TCP creates socket passage (SocketChannel) and corresponding NIO processor (NIOHandler) interface; Datagram passage (DatagramChannel) and corresponding NIO processor interface is created according to the connection request that UDP connects; Socket passage and corresponding NIO processor interface is created according to the connection request that HTTP connects.
S4:NIO communication thread is monitored each data-processing interface, has judged whether that data arrive, has if so, then entered S5, if not, then continues to monitor;
S5:NIO communication thread notice NIO network connecting module, and data are submitted to NIO network connecting module;
S6:NIO network connecting module after receiving the data, transfers to NIO data processing module to process, and described NIO data processing module comprises tcp data processing module, UDP message processing module and HTTP data processing module.NIO network connecting module by judging according to the interface channel of data to belong to that TCP connects, UDP connects, HTTP connect in any, and transfer to corresponding tcp data processing module, UDP message processing module, HTTP data processing module in NIO data processing module to process.
When NIO data processing module processes, if there is the incomplete situation of data receiver, show to connect disconnection, then feedback needs the message reconnected to NIO network connecting module; Do not receive the situation of data if occur, show to connect time-out, then point out NIO network connecting module to check interface channel and corresponding data-processing interface, and reconnect; If there is the situation of the error in data received, then notify that NIO network connecting module reassigns interface channel and corresponding data-processing interface.The troubleshooting function of NIO data processing module, improves the fault-tolerance of system, ensure that the stability of system cloud gray model.
The present invention is not limited to above-mentioned execution mode, and for those skilled in the art, under the premise without departing from the principles of the invention, can also make some improvements and modifications, these improvements and modifications are also considered as within protection scope of the present invention.The content be not described in detail in this specification belongs to the known prior art of professional and technical personnel in the field.

Claims (9)

1. based on a multi-protocol communication framework for android system, it is characterized in that: comprise the NIO thread pool module, NIO network connecting module and the NIO data processing module that connect successively;
Wherein, described NIO thread pool module is according at least one connection request received at every turn, and create a NIO communication thread, each connection request is sent to NIO network connecting module by described NIO communication thread;
Described NIO network connecting module creates corresponding interface channel and corresponding data-processing interface according to the type of each connection request, and the data received by data-processing interface send NIO data processing module to;
Described NIO data processing module is used for processing the data that NIO network connecting module transmits.
2., as claimed in claim 1 based on the multi-protocol communication framework of android system, it is characterized in that: the number scope of the connection request that described NIO thread pool module receives at every turn is 1 ~ 5.
3. as claimed in claim 1 based on the multi-protocol communication framework of android system, it is characterized in that: the type of described connection request comprises TCP connection, UDP connects and is connected with HTTP.
4. as claimed in claim 1 based on the multi-protocol communication framework of android system, it is characterized in that: described NIO data processing module comprises the HTTP data processing module of the tcp data processing module of process TCP connection data, the UDP message processing module of process UDP connection data and process HTTP connection data.
5., based on a multi-protocol communication method for multi-protocol communication framework described in claim 1, it is characterized in that, comprise the steps:
S1: initialization NIO thread pool module, and receive connection request, and NIO thread pool module receives at least one connection request at every turn;
After S2:NIO thread pool module receives at least one connection request described at every turn, just create a NIO communication thread, each connection request is sent to NIO network connecting module by described NIO communication thread;
S3:NIO network connecting module, according to the type of each connection request, creates corresponding interface channel and corresponding data-processing interface;
S4:NIO communication thread is monitored each data-processing interface, has judged whether that data arrive, has if so, then entered S5, if not, then continues to monitor;
S5:NIO communication thread notice NIO network connecting module, and data are submitted to NIO network connecting module;
S6:NIO network connecting module after receiving the data, transfers to NIO data processing module to process.
6. multi-protocol communication method as claimed in claim 5, is characterized in that: in step S1, and the type of described connection request comprises TCP connection, UDP connects and is connected with HTTP.
7. multi-protocol communication method as claimed in claim 6, is characterized in that: in step S3, NIO network connecting module, creates socket passage and corresponding NIO processor interface according to the connection request that TCP connects; Datagram passage and corresponding NIO processor interface is created according to the connection request that UDP connects; Socket passage and corresponding NIO processor interface is created according to the connection request that HTTP connects.
8. multi-protocol communication method as claimed in claim 7, is characterized in that: described NIO data processing module comprises tcp data processing module, UDP message processing module and HTTP data processing module; In step S6, NIO network connecting module after receiving the data, by judging according to the interface channel of data to belong to that TCP connects, UDP connects, HTTP connect in any, and transfer to corresponding tcp data processing module, UDP message processing module, HTTP data processing module in NIO data processing module to process.
9. multi-protocol communication method as claimed in claim 8, it is characterized in that: in described step S6, when NIO data processing module processes, if there is the incomplete situation of data receiver, show to connect and disconnect, then feedback needs the message reconnected to NIO network connecting module; Do not receive the situation of data if occur, show to connect time-out, then point out NIO network connecting module to check interface channel and corresponding data-processing interface, and reconnect; If there is the situation of the error in data received, then notify that NIO network connecting module reassigns interface channel and corresponding data-processing interface.
CN201410419975.8A 2014-08-25 2014-08-25 Multi-protocol communication framework and communication method based on Android system Pending CN104219231A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410419975.8A CN104219231A (en) 2014-08-25 2014-08-25 Multi-protocol communication framework and communication method based on Android system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410419975.8A CN104219231A (en) 2014-08-25 2014-08-25 Multi-protocol communication framework and communication method based on Android system

Publications (1)

Publication Number Publication Date
CN104219231A true CN104219231A (en) 2014-12-17

Family

ID=52100365

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410419975.8A Pending CN104219231A (en) 2014-08-25 2014-08-25 Multi-protocol communication framework and communication method based on Android system

Country Status (1)

Country Link
CN (1) CN104219231A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017041398A1 (en) * 2015-09-08 2017-03-16 安一恒通(北京)科技有限公司 Data transmission method and device
CN111404971A (en) * 2020-06-08 2020-07-10 季华实验室 Industrial robot network interface safety control method and device and electronic equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102800038A (en) * 2012-08-13 2012-11-28 南京鑫三强科技实业有限公司 Intelligence education E-card system platform based on internet of things and cloud computation
CN103345427A (en) * 2013-07-15 2013-10-09 四川公用信息产业有限责任公司 View switching system and method based on Android message handling mechanism
CN103455416A (en) * 2013-07-18 2013-12-18 北京航空航天大学 Pressure test method based on Android system intelligent device memory usage and CPU
CN103455355A (en) * 2013-09-05 2013-12-18 南京朗睿软件科技有限公司 Android equipment, and asynchronous data uploading method and device for AdapterView of Android equipment
US20140068632A1 (en) * 2012-09-06 2014-03-06 Box, Inc. Disabling the self-referential appearance of a mobile application in an intent via a background registration

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102800038A (en) * 2012-08-13 2012-11-28 南京鑫三强科技实业有限公司 Intelligence education E-card system platform based on internet of things and cloud computation
US20140068632A1 (en) * 2012-09-06 2014-03-06 Box, Inc. Disabling the self-referential appearance of a mobile application in an intent via a background registration
CN103345427A (en) * 2013-07-15 2013-10-09 四川公用信息产业有限责任公司 View switching system and method based on Android message handling mechanism
CN103455416A (en) * 2013-07-18 2013-12-18 北京航空航天大学 Pressure test method based on Android system intelligent device memory usage and CPU
CN103455355A (en) * 2013-09-05 2013-12-18 南京朗睿软件科技有限公司 Android equipment, and asynchronous data uploading method and device for AdapterView of Android equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
孙东风: "基于线程池和NIO技术构建高效的多协议Android通讯框架", 《HTTP://BLOG.CSDN.NET/DONGFENGSUN/ARTICLE/DETAILS/6154896》 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017041398A1 (en) * 2015-09-08 2017-03-16 安一恒通(北京)科技有限公司 Data transmission method and device
CN111404971A (en) * 2020-06-08 2020-07-10 季华实验室 Industrial robot network interface safety control method and device and electronic equipment
CN111404971B (en) * 2020-06-08 2020-10-23 季华实验室 Industrial robot network interface safety control method and device and electronic equipment

Similar Documents

Publication Publication Date Title
CN110034983B (en) Home equipment linkage method and system based on publish-subscribe message processing mechanism
CN102883134A (en) Screen sharing and controlling method for video conference system
CN105450779B (en) The method of one household appliance connection multiserver
CN103312528A (en) Heartbeat message sending method and user terminal
CN104038548A (en) Server system
CN102497534A (en) Distribution network full high definition video matrix system
CN104219231A (en) Multi-protocol communication framework and communication method based on Android system
CN105163339B (en) A kind of asymmetric long connection method and system of network access equipment buffering
CN104797004B (en) The method that automatic network-building is realized between master-slave equipment
CN103974022A (en) SIP-based building visual intercom method and system
CN106657076B (en) TCP service implementation method and device for network name space
CN110958291B (en) Industrial vehicle data transmission system and method
CN105141897A (en) Remote video monitoring system and method
CN107017915A (en) A kind of equipment and its method of work for realizing shared by multiple systems wireless network
CN102819252B (en) Method for realizing multi-redundancy of process control station in distributed control system
CN106411616B (en) A kind of device and method by 1553B bus management ethernet terminal
CN102843265B (en) Not resetting without the hot standby dual link method of perturbation of a kind of communication protocol
CN205942587U (en) Server
CN108508799A (en) A kind of long-range control method
CN102624567A (en) Hardware type network safety control server thermal backup device
CN103095562B (en) cloud computing intelligent gateway
CN102571515A (en) Interaction method of intelligent household appliances
CN102170562A (en) Network video service device
CN204906385U (en) Wireless public network communication module's interface arrangement
CN107070760A (en) A kind of remote multi-person monitoring intelligent house system and implementation method

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
AD01 Patent right deemed abandoned

Effective date of abandoning: 20190104

AD01 Patent right deemed abandoned