Function Reference


UDPRecv

Receives data from an opened socket

UDPRecv ( socketarray, maxlen [, flag] )

Parameters

socketarray The socket/array as returned by a UDPBind function.
maxlen max # of characters to receive.
flag [optional] Forces the function to return binary data if set to 1 (default is 0, and will auto detect between binary/string).
Forces the function to return receive from IP/port if set to 2. Results are returned in an Array : [0] data, [1] from IP, [2] from Port.
If you want both just use 3.

Return Value

Success: Returns binary/string sent by the opened socket or an array if flag = 2 or 3.
Failure: Returns "" and set @error.
@error: -1, -2 or -3 invalid socketarray.
windows API WSAGetError return value (see MSDN).

Remarks

For backwards compatibility reasons this function will try to return strings by default. If null (0x00) characters are received then the return value will be a binary type.
To force the function to always return binary data (the most sensible option) then use the "flag" parameter set to 1.

Related

BinaryLen, BinaryMid, UDPBind, UDPOpen

Example


;;This is the UDP Server
;;Start this first

; Start The UDP Services
;==============================================
UDPStartup()

; Register the cleanup function.
OnAutoItExitRegister("Cleanup")

; Bind to a SOCKET
;==============================================
Local $socket = UDPBind("127.0.0.1", 65532)
If @error <> 0 Then Exit

While 1
    Local $data = UDPRecv($socket, 50)
    If $data <> "" Then
        MsgBox(0, "UDP DATA", $data, 1)
    EndIf
    Sleep(100)
WEnd

Func Cleanup()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc   ;==>Cleanup