Powershell: UDP Client and Server

Hi,

these UDP client and server and simply used for testing if a specific UDP port is open

This is the server side. It listens at port 4444

# Server
$iPort = 4444
$Listen = New-Object System.Net.IPEndPoint ([IPAddress]::Any, $port)
$oSocket = New-Object System.Net.Sockets.UdpClient($iPort)
        while($true) {
          $aContent = $oSocket.Receive([ref]$Listen)
          [Text.Encoding]::ASCII.GetString($aContent)
      }
$oSocket.Close() 

And the client side

# Client
$iPort = 4444
$sSendToHost="localhost"
$oSocket = New-Object System.Net.Sockets.UdpClient
$aMessage=[System.Text.Encoding]::ASCII.GetBytes("TEST 1234")
$oSocket.Send($aMessage ,$aMessage.Length,$sSendToHost,$iPort)

Michael

Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.