La imagen tiene que ser menor de 65535 bytes.
Server que recibe la imagen
1 2 3 4 5 6 7 8 9 |
## Server $ip = [System.Net.IPEndPoint]::new([IPAddress]::Any,0) $udp = [System.Net.Sockets.UdpClient]::new(2020) $content = $udp.Receive([ref]$ip) [System.IO.File]::WriteAllBytes('screenshotcopy.bmp',$content) $udp.Close() |
Cliente que envía la imagen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
## Cliente $ip = [System.Net.IPEndPoint]::new([IPAddress]::Loopback,2020) $udp = [System.Net.Sockets.UdpClient]::new() $path = '.\captura.bmp' $Bytes = [System.IO.File]::ReadAllBytes($path) # length < 65507 # El tamaño máximo de un paquete IP que incluye todos los # encabezados es de 65535 bytes. Los encabezados IP y UDP se combinan # para al menos 28 bytes. Así que el tamaño máximo de la porción de datos # de un datagrama UDP es 65535-28 == 65507 $udp.Send($Bytes,$Bytes.Length,$ip) | Out-Null $udp.Close() |