문제

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