I can either send data throughout the udp protocol with the UdpClient.Send(byte array) or the UdpClient.Client.Send(stream) method. both methods work. the only differences are that on one method I pass a byte array and on the other I pass a stream.
quick example:
UdpClient udpClient = new UdpClient(localEndPoint);
// I can eather send data as:
udpClient.Send(new byte[] { 0, 1, 2 }, 3);
udpClient.Client.Send(new byte[5]);
Also which method will ensure that my data reaches it’s destination without loosing information? I have read that the udp protocol does not ensure that all bytes reach it’s destination thus is better for streaming video, audio but not for transferring files like I am doing. The reason why I am using udp instead of tcp is because it is very complicated to establish a tcp connection between two users that happen to be behind a router. I know it will be possible if one of the users enables port forwarding on his router. I managed to send data by doing what is called udp punch holing. udp punch holing enables you to establish a connection between two users that are behind a router with the help of a server. It will be long to explain how that work in here you can find lot’s of information if you google it. Anyways I just wanted to let you know why I was using udp instead tcp. I don’t now if it will be possible to send a file with this protocol making sure that no data is lost. maybe I have to create an algorithm. or maybe the UdpClient.Client.Send method ensures that data will be received and the UdpClient.Send method does not ensure that data will be received.
UDP does not guarantee data delivery or order of them. It only guarantees if you receive packet successfully, the packet is complete. You need to make your network communication reliable with your own implementation. The two functions should not make any difference.
UNIX Network Programming has a chapter for this topic. (22.5 Adding Reliability to a UDP Application). You can also take a look at libginble which supports NAT traversal function (with STUN or relay) and reliability of communication.
This article, Reliability and Flow Control, might also help you to understand one possible way to implement it. Good Luck!