Servidor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
##Server $port=2050 $IPEndPoint=New-Object System.Net.IPEndPoint([IPAddress]::Any,$port) $TcpListener=New-Object System.Net.Sockets.TcpListener $IPEndPoint $TcpListener.Start() $AcceptTcpClient=$TcpListener.AcceptTcpClient() $GetStream=$AcceptTcpClient.GetStream() $StreamReader=New-Object System.IO.StreamReader $GetStream $peticionrecibida=$StreamReader.ReadLine() if($peticionrecibida -match "peticion") { "Ha llegado la petición" } $StreamReader.Dispose() $GetStream.Dispose() $AcceptTcpClient.Dispose() $TcpListener.Stop() |
Cliente
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
##Client $port=2050 $TcpClient=New-Object System.Net.Sockets.TcpClient([IPAddress]::Loopback, $port) $GetStream = $TcpClient.GetStream() $StreamWriter = New-Object System.IO.StreamWriter $GetStream $positions='peticion' $StreamWriter.Write($positions) $StreamWriter.Dispose() $GetStream.Dispose() $TcpClient.Dispose() |