UDPBind
创建绑定到连接的套接字(socket).
UDPBind ( IPAddr, port )
参数
IPAddr
|
互联网协议点地址(IpV4) 如: "192.162.1.1".
|
port
|
创建套接字绑定的端口.
|
返回值
成功:
|
返回一个数组:
$aArray[1] 包含真实的套接字
$aArray[2] 包含指定的 IP 地址
$aArray[3] 包含端口.
有了这些信息才能在后面调用 UDPRecv(), 然后传递这个套接字数据结构/数组.
|
失败:
|
@error 设置 为非 0 值.
|
@error:
|
1 - IP 地址错误.
2 - 端口错误.
为 windows API WSAGetError 的返回值. (请查阅 MSDN).
|
相关
UDPCloseSocket, UDPOpen, UDPRecv, UDPSend
函数示例
#include <MsgBoxConstants.au3>
Example()
Func Example()
UDPStartup() ; Start the UDP service.
; Register OnAutoItExit to be called when the script is closed.
OnAutoItExitRegister("OnAutoItExit")
; Assign Local variables the loopback IP Address and the Port.
Local $sIPAddress = "127.0.0.1" ; 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(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not bind, Error code: " & $iError)
Return False
Else
MsgBox($MB_SYSTEMMODAL, "", "Bind successful.")
EndIf
; Close the Listening socket to allow afterward binds.
; While not closed, any other program can NOT bind to the same IP Address and Port.
UDPCloseSocket($aSocket)
EndFunc ;==>Example
Func OnAutoItExit()
UDPShutdown() ; Close the UDP service.
EndFunc ;==>OnAutoItExit
----------------------------------------
|