UDP Services

 

 

Syntax


FUNCTION UDPIN ( PORT ) AS STRING
FUNCTION LASTIP

SUB UDPOUT ( IP, PORT,  String )

Description


UDPIN and UDPOUT read or write a packet of data on the network using UDP protocol.
The IP address which the data is sent to or received from is designated by IPa.IPb.IPc.IPd eg. 192.168.0.122, which is packed into a 32 bit word.
Broadcast addressing is not supported for UDPIN or UDPOUT.
The port is designated by PORT.

NODE PING - A special feature of ARMweb listens on port 49152 (0xC000) for any UDP broadcast.
The node will then reply with its Name and IP to identify it on the network.
According to iana.org, The Dynamic and/or Private Ports are those from 49152 through 65535.
User applications should use ports above 49152 to avoid other conflicts.

UDPOUT automatically sets the node to listen on the given port.
This allows any responses to be buffered and subsequently read with UDPIN.
If an application wishes to just read UDPIN it is advised to call UDPIN once to clear any buffered data first.
Each call to UDPIN will wait up to one half second to receive data or return immediately upon receipt.
If no data was read the port is left open for reading, any incoming data will be buffered and available for subsequent calls.
The maximum size of the returned by UDPIN is 255 bytes.

This function requires version 7.36 of the firmware

Example

'send a string to UDP port 50000 of 192.168.0.122
UDPOUT ((192<<24)+(168<<16)+(0<<8)+122, 50000, "9876543210")

DIM Astr(100) as STRING

'sit and listen for any incoming UDP on port 50000
 
Astr = ""
WHILE Astr(0) = 0
  Astr = UDPIN  (50000)
  x = LASTIP
LOOP
PRINT Astr; " from "; x>> 24; "."; x>>16 and 255; "."; x>>8 and 255; ".";x and 255
 
Executing...
 
ABCDEFGHIJ from 192.168.15.122


See also