Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
c# Send telnet command WinForms
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Permudious" data-source="post: 462676" data-attributes="member: 55273"><p>Thanks! let me try TcpClient.Connect. It's always a local machine.</p><p>[automerge]1594793488[/automerge]</p><p>Okay it's kinda working for now.. only I have an if, else if, else case which checks a value if the value is < 10 than the message is -green if the value = 10 than the message is -red.</p><p>The value can be changed when the timer is ticking. So I assume that I need to close the tcp connect first before I can open it again. I have tried that but that isn't working.</p><p></p><p>[CODE=csharp]if (TotalIn <= 10)</p><p>{</p><p> var client = new TcpClient();</p><p> var hostname = "127.0.0.1";</p><p> client.Connect(hostname, 4000);</p><p></p><p> NetworkStream networkStream = client.GetStream();</p><p> networkStream.ReadTimeout = 5;</p><p></p><p> var writer = new StreamWriter(networkStream);</p><p></p><p> var message = "-green";</p><p> var reader = new StreamReader(networkStream, Encoding.UTF8);</p><p></p><p> byte[] bytes = Encoding.UTF8.GetBytes(message);</p><p> networkStream.Write(bytes, 0, bytes.Length);</p><p> client.Close();</p><p>}</p><p>else if (TotalIn == 1)</p><p>{</p><p> var client = new TcpClient();</p><p> var hostname = "127.0.0.1";</p><p> client.Connect(hostname, 4000);</p><p></p><p> NetworkStream networkStream = client.GetStream();</p><p> networkStream.ReadTimeout = 5;</p><p></p><p> var writer = new StreamWriter(networkStream);</p><p></p><p> var message = "-red";</p><p> var reader = new StreamReader(networkStream, Encoding.UTF8);</p><p></p><p> byte[] bytes = Encoding.UTF8.GetBytes(message);</p><p> networkStream.Write(bytes, 0, bytes.Length);</p><p> client.Close();</p><p>}</p><p>else</p><p>{</p><p> // no message</p><p>} [/CODE]</p><p></p><p>Whatever I do, the message will always send -green but the value is now 10, so it should be -red.</p></blockquote><p></p>
[QUOTE="Permudious, post: 462676, member: 55273"] Thanks! let me try TcpClient.Connect. It's always a local machine. [automerge]1594793488[/automerge] Okay it's kinda working for now.. only I have an if, else if, else case which checks a value if the value is < 10 than the message is -green if the value = 10 than the message is -red. The value can be changed when the timer is ticking. So I assume that I need to close the tcp connect first before I can open it again. I have tried that but that isn't working. [CODE=csharp]if (TotalIn <= 10) { var client = new TcpClient(); var hostname = "127.0.0.1"; client.Connect(hostname, 4000); NetworkStream networkStream = client.GetStream(); networkStream.ReadTimeout = 5; var writer = new StreamWriter(networkStream); var message = "-green"; var reader = new StreamReader(networkStream, Encoding.UTF8); byte[] bytes = Encoding.UTF8.GetBytes(message); networkStream.Write(bytes, 0, bytes.Length); client.Close(); } else if (TotalIn == 1) { var client = new TcpClient(); var hostname = "127.0.0.1"; client.Connect(hostname, 4000); NetworkStream networkStream = client.GetStream(); networkStream.ReadTimeout = 5; var writer = new StreamWriter(networkStream); var message = "-red"; var reader = new StreamReader(networkStream, Encoding.UTF8); byte[] bytes = Encoding.UTF8.GetBytes(message); networkStream.Write(bytes, 0, bytes.Length); client.Close(); } else { // no message } [/CODE] Whatever I do, the message will always send -green but the value is now 10, so it should be -red. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
c# Send telnet command WinForms
Top