Server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$endpoint = new-object System.Net.IPEndPoint ([system.net.ipaddress]::any, 8982) $listener = new-object System.Net.Sockets.TcpListener $endpoint $listener.start() $contador=0 do { $client = $listener.AcceptTcpClient() # will block here until connection $stream = $client.GetStream(); $reader = New-Object System.IO.StreamReader $stream $lines=$reader.ReadToEnd() $enc = [system.Text.Encoding]::Default $filebytes = $enc.GetBytes($lines) $contador=$contador+1 [System.IO.File]::WriteAllBytes('F:\power\video\capturas2\'+$contador+'.bmp', $filebytes) $reader.Dispose() $stream.Dispose() $client.Dispose() } while (1) |
Client
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function send-msg($file) { $client = New-Object System.Net.Sockets.TcpClient "localhost", 8982 $stream = $client.GetStream() $writer = New-Object System.IO.StreamWriter $stream $bytes = [System.IO.File]::ReadAllBytes($file) #$writer.WriteLine($bytes) $writer.Write($bytes,0,$bytes.length) $writer.Dispose() $stream.Dispose() $client.Dispose() } ls F:\power\video\captura\ | %{send-msg($_.FullName)} |