Function Reference


Create a socket bound to an incoming connection.

UDPBind ( IPAddr, port )


IPAddr Internet Protocol dotted address(IpV4) as "".
port port on which the created socket will be bound.

Return Value

Success: an array : $aArray[1] contains the real socket, $aArray[2] contains the specified IP address and $aArray[3] contains the port. We need this information in subsequent calls to UDPRecv(), where we pass this socket structure/array.
Failure: Sets the @error flag to non-zero.
@error: 1 - IPAddr is incorrect.
2 - port is incorrect.
Windows API WSAGetLastError return value (see MSDN).


UDPCloseSocket, UDPOpen, UDPRecv, UDPSend


#include <MsgBoxConstants.au3>


Func Example()
        UDPStartup() ; Start the UDP service.

        ; Register OnAutoItExit to be called when the script is closed.

        ; Assign Local variables the loopback IP Address and the Port.
        Local $sIPAddress = "" ; This IP Address only works for testing on your own computer.
        Local $iPort = 65532 ; Port used for the connection.

        ; Assign a Local variable the socket and bind to the IP Address and Port specified.
        Local $aSocket = UDPBind($sIPAddress, $iPort)

        ; If an error occurred display the error code and return False.
        If @error Then
                ; Someone is probably already binded on this IP Address and Port (script already running?).
                Local $iError = @error
                MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), "", "Could not bind, Error code: " & $iError)
                Return False
                MsgBox($MB_SYSTEMMODAL, "", "Bind successful.")

        ; Close the Listening socket to allow afterward binds.
        ; While not closed, any other program can NOT bind to the same IP Address and Port.
EndFunc   ;==>Example

Func OnAutoItExit()
        UDPShutdown() ; Close the UDP service.
EndFunc   ;==>OnAutoItExit