Embodiment
Below in conjunction with accompanying drawing a kind of data flow sending, receiving method and device based on UDP that the embodiment of the invention provides is described in detail.
As shown in Figure 1, first embodiment of a kind of data flow sending method based on UDP that the embodiment of the invention provides; In the process that realizes the embodiment of the invention, this method comprises:
101: with the multi-medium data cutting is the data segment that is not more than preset value; Because the multi-medium data that transmits based on udp protocol comprises: two types of video data and voice datas; Carry out cutting so the multi-medium data cutting just will be transferred to the video data and the voice data of client.Wherein, described preset value can be 128 bytes.
102: said data segment is encapsulated in the UDP bag;
Data segment after the said multi-medium data cutting is encapsulated in the UDP bag; Can video-data fragment after the cutting and audio data section be encapsulated in respectively in the user data UDP bag.
103: send the UDP bag that carries said UDP bag.
It should be noted that said UDP bag, comprising: sub-packet header type field, son bag load size field, son bag timestamp field and son bag payload data field.The sub-packet format of said UDP is as shown in the table:
Wherein, HeadType is a sub-packet header type field, is used to indicate the type in this sub-packet header; Size is a son bag load size field, is used to indicate the size of this child bag load, does not comprise the size of each field in the son bag; The size of said son bag load can not surpass 128 bytes; Time is a son bag timestamp field, is used to indicate the timestamp of this child bag.
Below each bit position of HeadType is elaborated, its form is as shown in the table:
Because that uses the UDP transmission has only video and two types of data of audio frequency, so available bit8 1 identifies that sub what comprise is video data; Using bit8 is that 0 what identify that son comprises is voice data.Because stream numbering is to identify a client and server end through 5 bit positions to set up after the connection number of transmission network stream simultaneously, therefore, can transmit 32 network flows simultaneously at most between the client and server end.That is to say that same connection can be transmitted a plurality of network flows simultaneously, is at most 32.
It should be noted that a plurality of network flows that the above same connection can be transmitted simultaneously can adjust maximum network flows according to the needs of actual conditions.
Below antithetical phrase bag load size field size is elaborated with son bag timestamp field time again; Above-described son bag load size field size and son bag timestamp field time all occur at every turn.Whether said field occurs deciding according to 2 bit positions of sub-packet header type.Its implication is represented respectively like following table:
Bits |
Sub-packet header long (byte) |
Explanation |
00 |
5 |
A current Zi Bao and a last sub-packet have the same channels numbering, different child bag load sizes and son bag timestamp |
01 |
4 |
A current Zi Bao and a last sub-packet have same channels numbering and son bag load size, different child bag timestamps |
10 |
2 |
A current Zi Bao and a last sub-packet have same channels numbering and son bag timestamp, different child bag load sizes |
11 |
1 |
A current Zi Bao and a last sub-packet have same channels numbering, son bag timestamp and son bag load size |
It is also to be noted that because the load data of a sub-packet is at most 128 bytes, transmit if each UDP bag only carries a sub-packet, then the packet header expense is relatively large.Non-divided when transmitting in order both to guarantee that UDP wraps in the IP layer, make UDP packet header expense reduce again, the embodiment of the invention can also adopt intersects the son bag and carries out transfer of data.Promptly allow a UDP bag once can transmit a plurality of child bags that bond together, at receiving terminal the bag content of bonding is recombinated through the numbering of distinguishing different passages and stream.Make that so once transmission can be transmitted polytype content, and the short child bag sheet of several different types can provide better real-time property.For example, in UDP bag load simultaneously the Voice & Video data, compared with sending audio pack and video packets successively, client can be carried out the synchronous of audio & video quickly.In addition, when packet drop occurring,, also less after losing to the influence of client terminal playing multi-medium data because the volume of transmitted data of each each type is little.
As shown in Figure 2, second embodiment of a kind of data flow sending method based on UDP that provides for the embodiment of the invention; In the process that realizes the embodiment of the invention, this method comprises:
201: when request is set up in the connection that receives the client transmission, judged whether that idle transmission channel and related resource are that client provides service;
202:, obtain the required multi-medium data of client if promising client provides the idle transmission channel and the related resource of service; Continue execution in step 204;
203:, send to connect and expire the message informing client if the idle transmission channel and the related resource of service are not provided for client.
204: with the multi-medium data cutting is the data segment that is not more than preset value; That is to say that the multi-medium data that client is needed carries out cutting, is the data segment that is not more than preset value with said multi-medium data cutting; This preset value can be 128 bytes;
205: said data segment is encapsulated in the UDP bag;
206:, said UDP bag is sorted according to time sequencing;
207: the load summation is not more than the approaching UDP bag bonding of said time sequencing of 546 bytes, and is encapsulated in the UDP bag;
It should be noted that; The embodiment of the invention is limited in the size that UDP wraps load in 546 bytes; Load adds UDP packet header length 8 bytes, UDP number field length 2 bytes and IP packet header length 20 bytes like this; Just be not higher than 576 bytes of public network MTU MTU, generally no longer need unpack.Therefore, when the sub-bag of described UDP institute data carried by data was not more than 128 bytes, a UDP bag can carry 4 UDPs bags.
It is also to be noted that, when encapsulation UDP bag, can carry out son bag bonding through following method:
1, arranges video frequency user data newspaper agreement son bag and audio user datagram protocol bag respectively according to time sequencing;
When 2, timestamp is kept off, according to timestamp sequential combination UDP bag;
3, timestamp near the time, if having video frequency user data newspaper agreement bag and audio user datagram protocol bag, then these two types sons are wrapped combined crosswise;
4, UDP bag total load length can not surpass 546 bytes.If a bonding sub-packet makes load possibly surpass 546 bytes, then should be with putting into next UDP bag by the child bag.
208: send the UDP bag that carries said UDP bag.
It is also to be noted that, after server end sends the said UDP bag of some,
Server end judges whether active client is connected with said server end;
If active client is connected with said server end, then continue to send the UDP bag;
If active client and said server end break off, then stop to send the UDP bag.
A kind of data flow dispensing device as shown in Figure 3, as to provide for the embodiment of the invention based on UDP; In the process that realizes the embodiment of the invention, this device comprises:
Judging unit 301 is used for when request is set up in the connection that receives the client transmission, having judged whether that idle transmission channel and related resource are that client provides service;
Data capture unit 302 if be used for idle transmission channel and the related resource that promising client provides service, obtains the required multi-medium data of client;
Data cutting unit 303, being used for the multi-medium data cutting is the data segment that is not more than preset value; This preset value can be 128 bytes;
Son bag acquiring unit 304 is used for said data segment is encapsulated in UDP bag; Wherein, said UDP wraps institute's data carried by data and is not more than 128 bytes;
Sequencing unit 305 is used for according to time sequencing, and said UDP bag is sorted;
Son bag bonding element 306 is used for the load summation is not more than the approaching UDP bag bonding of said time sequencing of 546 bytes, and is encapsulated in the UDP bag.
Information transmitting unit 307 is used to send the UDP bag that carries said UDP bag; If also be used for not providing the idle transmission channel and the related resource of service, send to connect and expire the message informing client for client.
It should be noted that this device also comprises:
After server end sends the said UDP bag of some, also comprise:
The connection judgment unit is used to judge whether active client is connected with said server end;
If active client is connected with said server end, then continue to send the UDP bag;
If active client and said server end break off, then stop to send the UDP bag.
As shown in Figure 4, first embodiment of a kind of data flow method of reseptance based on UDP that provides for the embodiment of the invention; In the process that realizes the embodiment of the invention, this method comprises:
401: receive the UDP bag that carries said UDP bag;
402: described UDP bag is sorted.
As shown in Figure 5, second embodiment of a kind of data flow method of reseptance based on UDP that provides for the embodiment of the invention; In the process that realizes the embodiment of the invention, this method comprises:
501: receive the UDP bag that carries said UDP bag;
502: described UDP bag is sorted;
503: whether the order of judging described UDP bag is continuous;
504:, then carry out corresponding packet loss and handle if the order of described User Datagram Protocol bag is discontinuous.For example: its data packet disorder that receives when client terminal to discover; Be the m that is numbered of the current UDP bag that should receive of client, and actual reception to the UDP bag be numbered n, and n is greater than m; The UDP bag that then is numbered between m and the n possibly lost, and also possibly postpone;
It should be noted that when the order of described UDP bag is discontinuous,
Start timer; Wait for a period of time, if promptly client wait for during this period of time in the UDP bag is reordered the bag of while latency delays.
Regularly overtime when timer, judge whether the said UDP bag of losing carries configuration information; That is to say that client is not received the packet of disappearance yet, then confirms said data-bag lost, and judges further whether the said UDP bag of losing carries configuration information after timer is regularly ultra; For example: after t that timer is fixed time is overtime, still lacks the UDP bag between m and the n and then think described UDP packet loss, judge the said UDP that loses wraps whether carry configuration information.
If the described UDP bag of losing carries configuration information, then send said UDP bag retransmission information; Owing between the channel number of transmitting multimedia data and the numbering of media stream corresponding relation is arranged; So when receiving the load bag of 5 of sub-packet header less thaies; And when contained channel number is current non-existent numbering in should the header packet information of child bag, can confirm to have taken place the situation of the load packet loss of new stream.When the load packet loss of new stream, whether retransmit whether the data playback information that depends on new stream is configuration information, whether that is to say to retransmit needs to confirm whether the data message that carries in this child bag is the configuration information that client is carried out data playback; If be configuration information, then retransmit; If not configuration information, then abandon.
If what the described UDP bag of losing carried is not configuration information, then the UDP bag according to current reception upgrades synchronously.For example: behind timer expiry; Client end will be numbered minimum UDP packet start after m; Each passage is sought first load that contains timestamp bag respectively; Utilize the timestamp in these loads bag to upgrade synchronously, before this timestamp the child bag all abandon, and according to these timestamps each passage is carried out corresponding synchronous and upgrades.
It is also to be noted that; When client is broken off from server; When perhaps causing connection termination owing to the network reason; Server should be able to obtain message, stops continue to send the UDP bag, and this can be through letting client receive that whenever some UDP bag back returns a feedback data packet to server end and realize.To accept this feedback data packet overtime or in the regular hour, do not receive feedback data packet when server end, and then server end can judge that connection interrupts, and stops to send the UDP bag.That is to say,
Receive the said UDP bag of some when client after,
Send feedback data packet; Wherein, said feedback data packet is used for announcement server end and client maintenance connection status.Here, client can be through starting timer, perhaps counter; The transmission of Control and Feedback packet; When described timer timing to or the counting of counter when satisfying condition, send feedback data packet.
A kind of data flow receiving system as shown in Figure 6, as to provide for the embodiment of the invention based on UDP; In the process that realizes the embodiment of the invention, this device comprises:
Information receiving unit 601 is used to receive the UDP bag that carries said UDP bag;
Data sorting unit 602 is used for described UDP bag is sorted.
Order judging unit 603 is used to judge whether the order of described UDP bag is continuous;
Packet loss processing unit 604 is discontinuous if be used for the order of described User Datagram Protocol bag, then carries out corresponding packet loss and handles.
It should be noted that when the order of described UDP bag is discontinuous, also comprise:
The timer start unit is used to start timer;
The information type judging unit is used for when timer regularly overtimely, judges whether the said UDP bag of losing carries configuration information;
The retransmission information transmitting element carries configuration information if be used for the described UDP bag of losing, and then sends said UDP bag retransmission information;
Synchronous updating block, if what be used for that the described UDP bag of losing carries is not configuration information, then the UDP bag according to current reception upgrades synchronously.
It is also to be noted that, after receiving said UDP bag,
The feedback data packet transmitting element is used to send feedback data packet; Wherein, said feedback data packet is used for announcement server end and client maintenance connection status.Concretely:
When client and server end carried out data interaction, client can also start the transmission that timer or counter come the Control and Feedback packet through start unit; Promptly
Said feedback data packet transmitting element, be used for when described timer timing to or the counting of counter when satisfying condition, send feedback data packet; Wherein, described feedback data packet is used for the connection status of announcement server end active client and server end.
A kind of data flow sending, receiving method and device based on UDP that the embodiment of the invention provides are through being the data segment that is not more than preset value with the multi-medium data cutting; And said data segment is encapsulated in the UDP bag; Transmission carries the UDP bag of said UDP bag and gives client.Wherein, Owing to describedly send to the UDP bag load of carrying in the UDP bag of client and be not more than preset value, saidly when the said UDP bag that carries UDP bag is transferred to the IP layer, need not carry out cutting and just can directly transmit.Compare with transmitting at IP after the prior art UDP cutting that load is bigger; The embodiment of the invention can not need cutting directly to transmit at the IP layer the said UDP bag that carries said UDP bag; Reduce the losing probability after the cutting of UDP message bag greatly, thereby improved the client-side multimedia play quality.
Description through above execution mode; One of ordinary skill in the art will appreciate that: realize that all or part of step in the foregoing description method is to instruct relevant hardware to accomplish through program; Described program can be stored in the computer read/write memory medium, and this program comprises the step like above-mentioned method embodiment when carrying out; Described storage medium, as: ROM/RAM, magnetic disc, CD etc.
The above; Be merely embodiment of the present invention, but protection scope of the present invention is not limited thereto, any technical staff who is familiar with the present technique field is in the technical scope that the present invention discloses; Can expect easily changing or replacement, all should be encompassed within protection scope of the present invention.Therefore, protection scope of the present invention should be as the criterion with the protection range of claim.