Okay so i know how to send packages. But i also now the limit (64kb), which means.
Anything more will be impossible to send in one package.
So my problem is, how do i send stuff that´s bigger?
I am guessing i must split with a for loop or something, but i don´t know how to do it.
1 2 3 4 5 6 7 8 9 10
byte[] u = imageToByteArray(holder);
byte[] buff = new byte[512];
int c = 0;
for (int i = 0; i < u.Length; i++)
{
buff[c] = u[i];
c++;
udpcap.Send(buff, buff.Length, adress.Address.ToString(), 1700);
}
Here is an example, but well it doesn´t work, i get (Index was outside the bounds of the array.)
The question you should really be asking is how to receive them. Sending fragmented data over UDP means it can arrive in any order, and may miss some (or all) fragments. Are you sure you don't need TCP?
I will test TCP if you think it´s better for this (as many do).
but i need an example, as i just don´t get how to write it.
The only thing i want to do is
Take a image
change it to byte array (as i think you must do this to send it?)
send the image
receive the image
decode it, and show it
The problem is only, sending and receiving.
i can do it with 1 package (with udp as i know how it works)
but i am unable to do it with more udp packages, and totally unable to do it with tcp no matter how many packages as it works differently.
An image is already an array of bytes. You just need to send and receive the data.
send and recv work pretty much the same with TCP and UDP. The problem with sending multiple packets with UDP is that you're not supposed to assume the rder, so you would usually mark each packet with a sequence number and then use that information to check you've got all the required packets and to help you re-assemble the packets once you've received them.
In the TCP case, the packets will arrive in order. So you just have receive in a loop until everthing's arrived. But you do have to astablish the connection first.
I have read but i don´t understand at all how to send in TCP.
From what i grasp, you are able to send an image(file etc) without dividing, as TCP does that for you.
But that´s it, i have no idea how to send.
As you don´t write the same as UDP where it´s straightforward, you send this array, it´s that long, to that IP.