Realize the intelligent terminal's long polling system system and method to car machineTechnical field
The present invention relates to the Internet, car networking, service platform and mobile terminal exploitation, particularly to mobile internet environmentUnder, carry out order delivery method timely, reliable to engine end.
Background technology
The Internet in prior art, mobile Internet network environment as follows:
The network infrastructure development of the Internet, through the development that the more than ten years are long-term, the most relatively stable and ripe, PC terminal,The ability of operating system has also reached higher level.
And mobile Internet, owing to relating to wireless telephony network base station, the development of 2G, 3G and 4G technology, it is steadyThough each side such as qualitative, bandwidth, resource distribution are gradually improved, but the current existence the most eventually also having many problems.Further, since moveIts essence " moved " of dynamic the Internet, adds that the development of intelligent terminal (smart mobile phone, panel computer) is later, the most also existsSituation about constantly developing, compared with the Internet, the situation that mobile Internet or low speed, instability, terminal capability are the most weak.AndOwing to it " moves " essence, in the short time, it is extremely difficult to the quality of the Internet.
So, inside the environment of the Internet, web application is due to the network facilities, the maturation of operating system, exploitationUsing and be easier, resource is the most sufficient.And mobile Internet is also intended to " worrying about petty gain or loss ".
Intelligent terminal's battery durable ability, system dormancy:
The battery durable ability of intelligent terminal is technical bottleneck all the time.In the case of using continuously, the overwhelming majoritySmart machine battery cannot be supported more than two hours.So not having the situation of external power source, intelligent terminal must frequencyDormancy numerous, long-time, this network application scene that will greatly affect under two kinds of network environments.
IP address, port resource:
Owing to needing dynamic IP address allocation (to refer not only to the IP of Internet portal here, also include within LANIP), the operation principle of router is all through port mapping, internal network (include PC, mobile phone, flat board, Wifi, 2G, 3G,4G) IP becomes external IP (typically public network IP) and corresponding port with port mapping, and maintains this mapping relations, could be normalGround is revised, E-Packet information, it is ensured that each ip internal, port and each outside ip, the communication of port.
But, the port resource of single ip address is limited, and theoretical upper limit is 65535 ports.For common wideFor router, this is the most sufficient.But, for large-scale network service, network backbone access point etc., ifIP inadequate resource, the resource of each several ten thousand ports of IP quickly can exhaust, thus affect normal communication.
Just because of this, all of router all can arrange ageing time for each port mapping relationship, if aging timeBetween count down toward 0, then port mapping relationship lost efficacy, this port be released to other connect use.If port all exhausts, then withoutThe most newly-built inside of method is connected with outside network.
Port mapping ageing time, than a lot of people imagine in short a lot.General domestic broadband router, time agingBetween be usually two or three minutes;Accessing part in cable broadband operator, ageing time is possibly less than two minutes.At radiotelephony networkNetwork operator accesses part (such as GPRS connection), and ageing time is even less than one minute.
It is to say, any one network communication (no matter being TCP or UDP), if there is no network message within a few minutesTransmission, the IP address port that it takies will be reclaimed by router.This time, no matter this communication of TCP or UDP will terminate.The fact that more cruel it is that the Internet is regarded as being formed by connecting by numerous router, and a network service generally requires logicalCrossing n router, each router can be the port mapping of a connection setup oneself.As long as one of them router reclaimsIts port, the most whole communicating interrupt.
Summary of the invention
The technical problem to be solved, it is simply that provide a kind of and realize the intelligent terminal long polling system system to car machineCar machine section is carried out ordering the most reliably issuing by system and method to realize engine end communication server.
The present invention solves described technical problem, employed technical scheme comprise that, it is achieved the intelligent terminal's long poll control to car machineSystem processed, including intelligent terminal, intelligent terminal server, engine end communication server and car machine, described intelligent terminal and intelligenceTerminal server connects, and intelligent terminal server is connected with engine end communication server, and engine end communication server is with car machine evenConnect;
Described intelligent terminal is used for issuing remote control command to intelligent terminal server;
Described intelligent terminal server for being forwarded to engine end communication server by remote control command;
Described engine end communication server is for setting up long connection with car machine, and is that a command line safeguarded by each car machineTeam;When receiving order, new remote control command is joined order to line up, during transmitting order to lower levels, remote control command is gone out team;WithTime, whether engine end communication server moment querying command line up to be empty, is then to maintain to be connected with long between car machine, otherwise underSay the word.
Concrete, described car machine, it is additionally operable to by, in sending HTTP request, arranging head keep-Alive:timeout=A;
Described engine end communication server, is additionally operable to arrange the long time-out time B that connects, and A < B, described time A and time BBy being manually set.
Further, when described car machine is additionally operable to send HTTP request, the long connection of detection is the most overtime, is then to set up and carThe new long connection of machine end communication server, otherwise by leading between the longest connection establishment and engine end communication serverNews.
Further, described engine end communication server, it is additionally operable to set up long-chain at engine end communication server and car machineAfter connecing, return link information to car machine;
Described car machine is additionally operable to receive after returning link information and again sends HTTP request, and engine end communication server detectsWhether order lines up to be empty, otherwise orders out team to be issued to car machine, is that then waiting time A returns heartbeat packet to car machine, maintenanceHTTP connection is not released.
The mobile phone terminal control method to the long polling system system of engine end is realized based on http protocol, bag for above-mentionedInclude following steps:
Intelligent terminal issues remote control command to intelligent terminal server, and intelligent terminal server is by remote control commandBeing forwarded to engine end communication server, engine end communication server is set up long connection with car machine, and is that each car machine safeguards oneOrder is lined up;When receiving order, new remote control command is joined order to line up, by remote control command during transmitting order to lower levelsGo out team;Meanwhile, whether engine end communication server moment querying command lines up to be empty, is then to maintain the length between car machine evenConnect, otherwise transmitting order to lower levels.
Concrete, engine end communication server is set up with car machine and is comprised the following steps long connection:
Car machine, in sending HTTP request, arranges head keep-Alive:timeout=A;
Engine end communication server arranges connection time-out time B, and A < B, and described time A and time B is by being manually set.
Further, described car machine sends HTTP request, if long connection has timed out, it is logical with engine end that system sets up car machineThe new long connection establishment communication of inquiry server, otherwise by the longest connection establishment communication, engine end communication server returnsLink information is to car machine.
Further, described car machine sends HTTP request, engine end communication server after receiving and returning link information againWhether sense command lines up to be empty, otherwise orders out team to be issued to car machine, is that then waiting time A returns heartbeat packet to car machine, dimensionHold HTTP connection not to be released.
The invention has the beneficial effects as follows: engine end communication server arranges and keeps http request the long time connected, whenTime within time threshold, connection will not discharge, and when car machine has new request, uses the connection that this has set up, will not createNew connection;If it exceeds time threshold, connection can be released, and when retransmiting new request, can re-establish connection;Car simultaneouslyAfter machine receives the order return of engine end communication server every time, all can again send this request, engine end communication server is receivedDuring to request, every time period A to engine end overtime return, by this polling mechanism, engine end, server send heartbeat packet dimensionHold http to connect and be not released, thus realize server and client is carried out order timely, reliable issue.
Accompanying drawing explanation
Fig. 1 is that the present invention realizes intelligent terminal to system authority in the long polling system system and method embodiment of car machineFigure;
Fig. 2 be the present invention realize intelligent terminal in the long polling system system and method embodiment of car machine car machine send pleaseSeek flow chart;
Fig. 3 is that the present invention realizes intelligent terminal's connection long to detection in the long polling system system and method embodiment of car machineThe most effectively flow chart.
Below in conjunction with the detailed description of the invention of embodiment, the foregoing of the present invention is described in further detail again.But this should not being interpreted as, the scope of the above-mentioned theme of the present invention is only limitted to Examples below.Thinking without departing from the above-mentioned technology of the present inventionIn the case of thinking, the various replacements made according to ordinary skill knowledge and customary means or change, all should be included in thisIn bright scope.
Detailed description of the invention
Below in conjunction with the accompanying drawings and embodiment describe in detail technical scheme:
The ageing time that the present invention is directed to the mapping of prior art middle port causes port to be recovered thus causes connecting being releasedThe problem put, it is provided that a kind of realize the intelligent terminal's long polling system system to car machine, including intelligent terminal, intelligent terminal's serviceDevice, engine end communication server and car machine, described intelligent terminal is connected with intelligent terminal server, intelligent terminal server and carMachine end communication server connects, and engine end communication server is connected with car machine;Described intelligent terminal is used for issuing and remotely controls to orderOrder is to intelligent terminal server;Described intelligent terminal server for being forwarded to engine end Communications service by remote control commandDevice;Described engine end communication server is for setting up long connection with car machine, and safeguards that an order is lined up for each car machine;ReceiveDuring order, new remote control command is joined order to line up, during transmitting order to lower levels, remote control command is gone out team;Meanwhile, car machineWhether end communication server moment querying command lines up to be empty, is then to maintain to be connected with the length between car machine, otherwise transmitting order to lower levels.Realizing the mobile phone terminal control method to the long polling system system of engine end for above-mentioned based on http protocol, intelligent terminal issuesRemote control command is to intelligent terminal server, and remote control command is forwarded to engine end Communications service by intelligent terminal serverDevice, engine end communication server is set up long connection with car machine, and is safeguarded that an order is lined up for each car machine;Receiving will when orderingNew remote control command joins order and lines up, and during transmitting order to lower levels, remote control command is gone out team;Meanwhile, engine end communication garmentWhether business device moment querying command lines up to be empty, is then to maintain to be connected with the length between car machine, otherwise transmitting order to lower levels.Engine end leads toInquiry server arranges and keeps http request the long time connected, and when within time threshold, connection will not discharge, Che JiyouDuring new request, use the connection that this has set up, new connection will not be created;If it exceeds time threshold, connection can be releasedPut, when retransmiting new request, connection can be re-established;Car machine receives the order return of engine end communication server every time simultaneouslyAfter, all can again send this request, when engine end communication server receives request, every time period A to engine end overtime return,By this polling mechanism, engine end, server send heartbeat packet and maintain http connection not to be released, thus realize server to visitorFamily end carries out order timely, reliable and issues.
Embodiment
HTTP be a request<prominent example of->response modes, i.e. user end to server send a solicited message,Server responds this information.In old HTTP version, each request will be created a new client-> serviceThe connection of device, sends request on this connection, then receives request.Such pattern has the advantage the biggest to be exactly, itThe simplest, it is readily understood that and programming realization;It also has a shortcoming the biggest to be exactly that its efficiency is the lowest, therefore Keep-Alive is proposed to solve inefficient problem.And Keep-Alive (keeping connecting) function makes client arrive server endConnection continuous and effective, when occurring the subsequent requests of server, Keep-Alive function avoids foundation or again buildsVertical connection.
This example be aiming at http keep connect this mechanism, it is achieved server client is carried out timely, order reliablyOrder issues.
System structure as it is shown in figure 1, include intelligent terminal, intelligent terminal server, engine end communication server and car machine,Described intelligent terminal is connected with intelligent terminal server, and intelligent terminal server is connected with engine end communication server, engine endCommunication server is connected with car machine;Described intelligent terminal is used for issuing remote control command to intelligent terminal server;Described intelligenceCan be used for being forwarded to remote control command engine end communication server by terminal server;Described engine end communication server is used forSet up long connection with car machine, and safeguard that an order is lined up for each car machine;When receiving order, new remote control command is addedEnter and line up to order, during transmitting order to lower levels, remote control command is gone out team;Meanwhile, engine end communication server moment querying command rowWhether team is empty, is then to maintain to be connected with the length between car machine, otherwise transmitting order to lower levels.
It is as follows that engine end is connected implementation with the http length of the communication server:
1. engine end is in the Http request sent, and arranges head Keep-Alive:timeout=A;(server will waitTreat that time period A just returns);
2. engine end communication server arranges connection time-out time B, and A < B, and described time A and time B is by being manually set.The servers such as IIS, Apache arrange the time B that http request keeps connect, and when within time threshold B, connection will notRelease, when engine end has new request, uses the connection that this has set up, will not create new connection.If it exceeds time thresholdValue B, connection can be released, and when retransmiting new request, can re-establish connection.
System work time, engine end sends under mobile network environment maintain connection http request, when IP address change,The reasons such as network environment disconnect this request that will resend, as shown in Figure 2;If long connection has timed out, system sets up carMachine is connected, otherwise by the longest connection establishment communication with the new length of engine end communication server.
And after car machine receives the link information that engine end communication server returns every time, all can again send this request, carWhen machine end communication server receives request, every time period A, client timeout is returned.By this polling mechanism, engine end, clothesBusiness device sends heartbeat packet and maintains http connection not to be released.And when service end has order to issue, returned by this request, and notIt is to return heartbeat packet.The most as shown in Figure 3.Wherein, HTTP effectively returns and includes the return of order and without the return ordered, and hasTime of return < the A of order;Time of return=A without order.But, whether comprising order no matter returning, returning all at TCP chainConnect in holding time and carry out, i.e. A < B.Returning if effectively returning, no matter whether this return includes order, being all explanation,Engine end communication server aspect safeguards the TCP channel having present communications, needs again to be initiated under order by this passage at onceSend out request;And return value is if overtime return, illustrate that this passage had lost efficacy, again will set up new when of requestTCP channel.The command number that can carry due to HTTP request only has one, and all orders issue server end and use queueCache and all of do not had transmitting order to lower levels, when upper once HTTP request arrives, whether had effective order data according to threshold decisionNeeds issue.
Considering the delay under mobile network environment, the value of B-A need to be in OK range, it is ensured that before Connection Release, and oneDirectly heartbeat packet is had to send.