受信
$Udp = New-Object Net.Sockets.UdpClient -ArgumentList 54321
$Sender = $null
while ($true) {
if ($Udp.Available) {
$Buffer = $Udp.Receive([ref]$Sender)
$MessageString = [Text.Encoding]::UTF8.GetString($Buffer)
Write-Host $MessageString
}
Start-Sleep -m 500
}
送信
$Udp = New-Object Net.Sockets.UdpClient
$ByteData = [Text.Encoding]::UTF8.GetBytes('Hello')
$Udp.Send($ByteData, $ByteData.Length, '192.168.11.7', '54321')
$Udp.Close()