利用UDPSend、UDPRecv
(单击环境实验成功,从帮助文件里的例子改过来的,局域网应该也可以.....)
server端代码#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Local $msg ,$data
GUICreate("My GUI Button")
GUISetState()
UDPStartup()
OnAutoItExitRegister("Cleanup")
Local $socket = UDPBind("127.0.0.1", 65532)
If @error <> 0 Then Exit
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
EndSelect
$data = UDPRecv($socket, 50)
If $data <> "" Then
Run($data)
EndIf
WEnd
Func Cleanup()
UDPCloseSocket($socket)
UDPShutdown()
EndFunc
client端#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Local $Button_2, $msg
GUICreate("My GUI Button")
Opt("GUICoordMode", 2)
Local $Button_2 = GUICtrlCreateButton("Button Test", 0, -1)
GUISetState()
UDPStartup()
OnAutoItExitRegister("Cleanup")
Local $socket = UDPOpen("127.0.0.1", 65532)
If @error <> 0 Then Exit
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button_2
Local $status = UDPSend($socket, "C:\WINDOWS\notepad.exe")
If $status = 0 then
MsgBox(0, "错误", "当发送 UDP 消息时发生错误: " & @error)
Exit
EndIf
EndSelect
WEnd
|