![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | problem with very simple tcpclient in powershell Hi there, I created a server in C# using TcpListner which is working fine. To connect to that server, i created a powershell script as follows: $s = new-object System.Net.Sockets.TcpClient("127.0.0.1", 4099) $str = $s.GetStream $wrtr = new-object System.IO.StreamWriter($str) $wrtr.WriteLine("Hello world!"); $wrtr.Flush $wrtr.Close(); $s.Close() Now, this is a very simple script and the SAME EQUIVALENT when written in C# works fine. But when i run this from the powershell, i get no errors, the Server definitely detects the connection, but it NEVER receives anything sent from WriteLine(). The same code written in C# works fine... even WriteLine() works fine in C# but not powershell. I do not get any error message either. What might be going wrong? Any help is appreciated. Thank you Invictus |
My System Specs![]() |
| | #2 (permalink) |
| | Re: problem with very simple tcpclient in powershell Not sure why you aren't getting an error but you need parenthases after GetStream otherwise the return value will be MethodInfo's. Josh "Invictus" <subrat@xxxxxx> wrote in message news:BFC0F279-0630-441B-B412-2F2D3843176B@xxxxxx Quote: > Hi there, > > I created a server in C# using TcpListner which is working fine. To > connect to that server, i created a powershell script as follows: > > $s = new-object System.Net.Sockets.TcpClient("127.0.0.1", 4099) > $str = $s.GetStream > $wrtr = new-object System.IO.StreamWriter($str) > $wrtr.WriteLine("Hello world!"); > $wrtr.Flush > $wrtr.Close(); > $s.Close() > > Now, this is a very simple script and the SAME EQUIVALENT when written in > C# works fine. > > But when i run this from the powershell, i get no errors, the Server > definitely detects the connection, but it NEVER receives anything sent > from WriteLine(). The same code written in C# works fine... even > WriteLine() works fine in C# but not powershell. > > I do not get any error message either. What might be going wrong? > > Any help is appreciated. > > Thank you > Invictus |
My System Specs![]() |
| | #3 (permalink) |
| | Re: problem with very simple tcpclient in powershell Invictus wrote: Quote: > Hi there, > > I created a server in C# using TcpListner which is working fine. To > connect to that server, i created a powershell script as follows: > > $s = new-object System.Net.Sockets.TcpClient("127.0.0.1", 4099) > $str = $s.GetStream > $wrtr = new-object System.IO.StreamWriter($str) > $wrtr.WriteLine("Hello world!"); > $wrtr.Flush > $wrtr.Close(); > $s.Close() > > Now, this is a very simple script and the SAME EQUIVALENT when written > in C# works fine. thing, you don't have your Flush method specified properly, it should be: $wrtr.Flush() (Semi-colons aren't required in PowerShell unless you put things on the same line.) Marco |
My System Specs![]() |
| | #4 (permalink) |
| | Re: problem with very simple tcpclient in powershell Josh Einstein wrote: Quote: > Not sure why you aren't getting an error but you need parenthases after > GetStream otherwise the return value will be MethodInfo's. $s = new-object System.Net.Sockets.TcpClient("127.0.0.1", 8001) $str = $s.GetStream() $wrtr = new-object System.IO.StreamWriter($str) $wrtr.Write("Test"); $wrtr.Flush(); $wrtr.Close(); $s.Close() You had *2* spots where you were missing the "()" on a method. Marco |
My System Specs![]() |
| | #5 (permalink) |
| | Re: problem with very simple tcpclient in powershell Marco Shaw [MVP] wrote: Quote: > Josh Einstein wrote: Quote: >> Not sure why you aren't getting an error but you need parenthases >> after GetStream otherwise the return value will be MethodInfo's. > There you go. I missed that one, so if you do this, it does work: > > $s = new-object System.Net.Sockets.TcpClient("127.0.0.1", 8001) > $str = $s.GetStream() > $wrtr = new-object System.IO.StreamWriter($str) > $wrtr.Write("Test"); > $wrtr.Flush(); > $wrtr.Close(); > $s.Close() > > You had *2* spots where you were missing the "()" on a method. > > Marco equally well now. Marco |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| simple problem | Network & Sharing | |||
| Simple Intellitype pro problem? | Drivers | |||
| Help with simple keyboard problem | General Discussion | |||
| TCPClient Thread | .NET General | |||