Skip to content

Instantly share code, notes, and snippets.

@jtuttas
Created January 22, 2014 13:50
Show Gist options
  • Save jtuttas/8559044 to your computer and use it in GitHub Desktop.
Save jtuttas/8559044 to your computer and use it in GitHub Desktop.
UDP Client / Server
$port=2021
$endpoint = new-object System.Net.IPEndPoint ([IPAddress]"10.13.6.100",$port)
$udpclient=new-Object System.Net.Sockets.UdpClient
$b=[Text.Encoding]::ASCII.GetBytes('Is anyone there!')
$bytesSent=$udpclient.Send($b,$b.length,$endpoint)
$udpclient.Close()
$port=2021
$endpoint = new-object System.Net.IPEndPoint ([IPAddress]::Any,$port)
$udpclient=new-Object System.Net.Sockets.UdpClient $port
$content=$udpclient.Receive([ref]$endpoint)
[Text.Encoding]::ASCII.GetString($content)
$udpclient.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment