Skip to content

Instantly share code, notes, and snippets.

@ariel-co
ariel-co / Start-TCPListener.ps1
Created December 24, 2025 01:40 — forked from jdgregson/Start-TCPListener.ps1
Simple example of listening on a port and reading from a socket in PowerShell.
$listener = [System.Net.Sockets.TcpListener]9999
$listener.Start()
while ($true) {
$client = $listener.AcceptTcpClient()
$rEndpoint = $client.client.RemoteEndPoint
$data = ""
$stream = $client.GetStream()
$buffer = New-Object System.Byte[] 1024
while ($client.Connected -and $stream.DataAvailable -and
($i = $stream.Read($buffer, 0, $buffer.Length)) -ne 0) {