Contenidos
Servidor (envía la posición del ratón al cliente)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ip = New-Object System.Net.IPEndPoint ([IPAddress]::Loopback,2021) for(1) { $udp = New-Object System.Net.Sockets.UdpClient $enviar = [System.Windows.Forms.Cursor]::Position.x.ToString()+"*"+[System.Windows.Forms.Cursor]::Position.y.ToString() $mensaje = [Text.Encoding]::ASCII.GetBytes($enviar) $udp.Send($mensaje,$mensaje.length,$ip) | Out-Null start-sleep -Seconds 2 } $udp.Close() |
Cliente (recibe la posición del servidor y la representa)
1 2 3 4 5 6 7 8 9 10 11 12 |
$ip = New-Object System.Net.IPEndPoint ([IPAddress]::Loopback,0) for(1) { $udp = New-Object System.Net.Sockets.UdpClient 2021 $posiciones = [Text.Encoding]::ASCII.GetString($udp.Receive([ref]$ip)) $posiciones ([Int]$posiciones.split("*")[0]+5) [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((([Int]$posiciones.split("*")[0]+100)),$posiciones.split("*")[1]) start-sleep -Seconds 2 $udp.Close() } |