UDP

Overview

UDP is a Dyalog cover class for Asynchronous UDP/IP Communication using the .Net UdpClient object. It is using the methods WriteAsync and ReadAsync available with .Net 4.5 for asynchronous communication that will not block the calling thread during the communication process. It is used to requests data from an Internet resource using UDP (User Datagram Protocol) over IP (Internet Protocol) like for home automation, data acquisition and process control.
An application using UDP prepares a packet and sends it to the receiver's address without first checking to see if the receiver is ready to receive a packet. If the receiving end is not ready to receive a packet, the packet is lost. In practice, UDP is quite reliable as long as the receiving socket is active and is processing data as quickly as it arrives. This is particularly the case when used on a private network. The application that is using UDP must be prepare to resend the data in case that it did not arrive to the receiving end.

Typical Usage

Since UDP is a connectionless protocol there is no need to connect before sending the bytes.

Instantiating the class

      udp ← ⎕NEW UDP

After instantiating the class the Fields _PortTimeOut and _Retries are accessible. _PortTimeOut is the Time in milliseconds to Wait for a UdpClient that is not Active (Receiving Nothing), if exceeded Windows Stop Waiting and returns the Control to the Calling Application. The default value is 250 milliseconds. _Retries is the number of times that the UdpClient will try to send the data if nothing is received. The default value is 3.

Sending the Data

The method SendReceive is used to send the data as numbers from 0 to 255 (bytes). The response contains the data received. To convert characters to bytes use ⎕UCS to do the conversion.

     r ← udp.SendReceive(bytes ip port)

     ⍝ bytes = Bytes (as Numbers 0 to 255) to be Written to the Communication Port
     ⍝ ip    = IP Address where to send the bytes in characters ('192.168.1.1') or numbers (192 168 1 1)
     ⍝ port  = Port Number to send the bytes (0 - 65535)

     ⍝ r[1] = 1 for Success, 0 for Failure
     ⍝ r[2] = Response if Success, Literal Error if Failure

There is no need to close the connection since there is no connection that is made before sending the data.

How to install UDP in your workspace

  1. Download UDP.v1.1.txt

  2. Do a Select all (Ctrl+A) and a copy (Ctrl+C).
  3. In your workspace execute )ed ○ UDP

  4. Paste (Ctrl+V) the text into the Dyalog editor
  5. Press Escape and ')save' your workspace

Version Information

 Version 1.1 January 2016, Pierre Gilbert

Original author:

Pierre Gilbert

Responsible:

PierreGilbert

Email:

<apgil AT SPAMFREE videotron DOT ca>


See also: netTCP netCOM


CategoryDyalog - CategoryDyalogDotNet - CategoryDotNet

netUDP (last edited 2016-01-09 14:35:32 by PierreGilbert)