Receives data from an opened socket
UDPRecv ( socketarray, maxlen [, flag] )
| 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. |
| 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). |
;;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