C # super simple Telnet (TcpClient) client,

Source: Internet
Author: User

C # super simple Telnet (TcpClient) client,

Based on Sockets

Nothing to say, the code shows all

1 using System; 2 using System. collections. generic; 3 using System. linq; 4 using System. text; 5 using System. net. sockets; 6 using System. IO; 7 8 namespace ConsoleApplication1 9 {10 class Program11 {12 public static NetworkStream; 13 public static TcpClient tcpclient; 14 public static string ip; 15 public static int port; 16 static void Main (string [] args) 17 {18 Console. writeLine ("target IP:"); 19 ip = Console. readLine (); 20 Console. writeLine ("Target Port:"); 21 port = int. parse (Console. readLine (); 22 23 Run (); 24} 25 26 static public void Run () 27 {28 tcpclient = new TcpClient (ip, port ); // connect to the server 29 stream = tcpclient. getStream (); // get the network data stream object 30 StreamWriter sw = new StreamWriter (stream); 31 StreamReader sr = new StreamReader (stream); 32 while (true) 33 {34 // Read Echo35 // Set ReadEcho Timeout36 stream. read Timeout = 10; 37 try38 {39 while (true) 40 {41 char c = (char) sr. read (); 42 if (c <256) 43 {44 if (c = 27) 45 {46 while (sr. read ()! = 109) {} 47} 48 else49 {50 Console. write (c); 51} 52} 53} 54} 55 catch56 {57 58} 59 // Send limit 60 sw. write ("{0} \ r \ n", Console. readLine (); 61 sw. flush (); 62} 63} 64 65} 66}TcpClient

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.