Question

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?

Était-ce utile?

La solution

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);

Autres conseils

You should convert to char or use this:

StreamReader reader = new StreamReader(stm);
string text = reader.ReadToEnd();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top