MATLAB: Transferring data between two computers using udp.

udp

In this post: http://blogs.mathworks.com/loren/2011/05/27/transferring-data-between-two-computers-using-matlab, how can I make the same process, but using UDP instead of tcpip?
Thanks.

Best Answer

If you do not have the Instrument Control Toolbox, look in the File Exchange for tcpudpip()
Note: udp is inherently unreliable.
  • routers and switches are permitted to drop udp packets
  • routers and switches are permitted to reorder udp packets even on the same device
  • network problems can happen at any time, and udp does not make any attempt to discover or recover from that
  • udp makes no attempt to determine whether packets were received successfully
  • TCP packets can end up dropped by network equipment if they are overloaded, but the network equipment that is overloaded has to give them higher priority than any udp packets it may be carrying
  • TCP packets with the same destination are not to be reordered on any one network device
  • However, TCP packets can end up being transmitted over different routes so they can end up being received out of order. Depending on how the destination is programmed, the packets that arrive too early are either retained for a while (hoping that the missing packet will arrive) or are discarded -- so TCP data is never received out of order by the application
  • TCP replies automatically convey information about how much data has been received successfully so the sending system knows what the receiver got
  • Although data packets can go missing, the TCP protocol has built-in timers to detect that something has gone missing and will re-request it or re-send it. The original TCP protocol would wait forever for a network connection to be restored, but these days pretty much everyone implements a time-out system to let you know that the data connection went away
UDP can be faster when it works. But if you are transmitting a file, you want be sure that the entire file has been received and in order, an application for which TCP is more suitable. You can implement the same kinds of protocols with UDP, but by the time you finish taking care of all the things that can go wrong, you end up having re-implemented TCP (and usually you would have re-implemented it poorly....)