Equipo 1 (servidor)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
##Server $ip = New-Object System.Net.IPEndPoint ([IPAddress]::Any,0) $udp = New-Object System.Net.Sockets.UdpClient 2020 do{ try { $content = $udp.Receive([ref]$ip) $posicion = [Text.Encoding]::ASCII.GetString($content) $posicion } catch { } }while($posicion.split(",")[0] -ne 0) $udp.Close() |
Equipo 2 (cliente)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
## Cliente $ip = New-Object System.Net.IPEndPoint ([IPAddress]::Loopback,2020) $udp = New-Object System.Net.Sockets.UdpClient do{ try { $posicion = [String]([System.Windows.Forms.Cursor]::Position.X) ` + "," + [String]([System.Windows.Forms.Cursor]::Position.Y) $posicion $mensaje = [Text.Encoding]::ASCII.GetBytes($posicion) $udp.Send($mensaje,$mensaje.length,$ip) | Out-Null } catch { } }while($posicion.split(",")[0] -ne 0) $udp.Close() |