Saturday, 17 August 2013

UDP sending data=?iso-8859-1?Q?=2C_something_i_don=B4t_quite_understand?=

UDP sending data, something i don´t quite understand

Okay from my knowledge UDP works like this:
You have data you want to send, you say to the UDP client, hey send this
data.
The UDP client then says, sure why not, and sends the data to the selected
IP and Port.
If it get´s through or in the right order is another story, it have sent
the data, you didn´t ask for anything else.
Now from this perspective, it´s pretty much impossible to send data and
assemble it. for example, i have a 1mb image, and i send it.
So i send divide it in 60kb files (or something to fit the packages), and
send them one by one from first to last.
So in theory, if all get´s added, the image should be exactly the same.
But, that theory breaks as there is no law that tells the packages if it
can arrive faster or slower than another, so it may only be possible if
you make some kind of wait timer, and hope for the best that the arrive in
the order they are sent.
Anyway, what i want to understand is, why does this work:
void Sending(object sender, NAudio.Wave.WaveInEventArgs e)
{
if (connect == true && MuteMic.Checked == false)
{
udpSend.Send(e.Buffer, e.BytesRecorded,
otherPartyIP.Address.ToString(), 1500);
}
}
Recieving:
while (connect == true)
{
byte[] byteData = udpReceive.Receive(ref remoteEP);
waveProvider.AddSamples(byteData, 0, byteData.Length);
}
So this is basically, it sends the audio buffer through udp.
The receiving par just adds the udp data received in a buffer and plays it.
Now, this works.
And i wonder.. why?
How can this work, how come the data is sent in the right order and added
so it appears as a constant audio stream?
Cause if i would to this with an image, i would probably get all the data.
But they would be in a random order probably, and i can only solve that by
marking packages and stuff like that. And then there is simply no reason
for it, and TCP takes over.
So if someone can please explain this, i just don´t get it.

No comments:

Post a Comment