S:
;;这是一个 UDP 服务器
;;Start this first
; Start The UDP Services
;==============================================
UDPStartup()
; Bind to a SOCKET
;==============================================
$socket = UDPBind("127.0.0.1", 65532)
If @error <> 0 Then Exit
While 1
$data = UDPRecv($socket, 500,1)
If $data <> "" Then
MsgBox(0, "UDP 数据", BinaryToString($data,4), 1)
EndIf
sleep(100)
WEnd
Func OnAutoItExit()
UDPCloseSocket($socket)
UDPShutdown()
EndFunc
C:
;;This is the UDP Client
;;Start the server first
; Start The UDP Services
;==============================================
UDPStartup()
; Open a "SOCKET"
;==============================================
$socket = UDPOpen("127.0.0.1", 65532)
If @error <> 0 Then Exit
$n=0
While 1
Sleep(2000)
$n = $n + 1
$status = UDPSend($socket, StringToBinary("测试使用中文发送消息 #" & $n & '中文,english,1234567',4))
If $status = 0 then
MsgBox(0, "错误", "当发送 UDP 消息时发生错误: " & @error)
Exit
EndIf
WEnd
Func OnAutoItExit()
UDPCloseSocket($socket)
UDPShutdown()
EndFunc
|