UDPINOUT
 
Syntax

UDPIN IPa,IPb,IPc,IPd,PORT, [ IOList ]
UDPOUT IPa,IPb,IPc,IPd,PORT, [ IOList ]
 IOList =  variable stringname$ \length| arrayname \count   [, InputList]

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.
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 reponses 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 IOList is 127 bytes.

Example

'send a string to UDP port 50000 of 192.168.0.22
UDPOUT 192,168,0,122, 50000, ["9876543210"]

'assume there is a reply from 192.168.0.122
UDPIN 192,168,0,122, 50000, [A$]
PRINT A$

'clear the input buffer
FOR I=0 TO 9
A$(I) = 0
NEXT I

'sit and listen for any incoming UDP on port 50000
while 1
  UDPIN 192,168,0,122, 50000, [A$]
  if A$(0) > 0 then
    PRINT A$     'print it
    FOR I=0 TO 9 'and clear the buffer
      A$(I) = 0
    NEXT I
  endif
loop

Differences from other BASICs

See also