I want to telnet program for some cisco devices in our company. I'm using this code:

String str = Console.ReadLine();
Stream stm = tcpClient.GetStream();

ASCIIEncoding asen = new ASCIIEncoding();

byte[] bb = new byte[100];

int k = stm.Read(bb, 0,100);

for(int i=0;i<k;i++)
{ 
   Console.WriteLine(Convert.ToString(bb[i])); 
}

but it returns just some numbers can you say what is wrong or different approach?

有帮助吗?

解决方案

you print byte value, it you want to print the string from those byte try using the below code (instead of the for loop):

            byte[] bb = new byte[100];

            int k = stm.Read(bb, 0,100);
            Console.WriteLine(System.Text.Encoding.Default.GetString(bb));

You can change the Encoding also, read the String.Text.Encoding_properties, for example the Ascii encoding

  // Create an ASCII encoding.
  Encoding ascii = Encoding.ASCII;

  String decodedString = ascii.GetString(bb);

其他提示

You should convert to char or use this:

StreamReader reader = new StreamReader(stm);
string text = reader.ReadToEnd();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top