2009-06-27 41 views

Respuesta

4

Para tareas simples (como la conexión a un dispositivo de hardware especializado con interfaz tipo telnet) que conecta vía el zócalo y simplemente enviar y recibir los comandos de texto pueden ser suficientes.

Si desea conectarse al servidor telnet real, puede necesitar manejar secuencias de escape de telnet, enfrentar emulación de terminal, manejar comandos interactivos, etc. Usar un código ya probado como Minimalistic Telnet library from CodeProject (gratis) o alguna biblioteca comercial de Telnet/Terminal Emulator (como nuestro Rebex Telnet) puede ahorrarle algo de tiempo.

siguiente código (tomado de this url) muestra cómo usarlo:

// create the client 
Telnet client = new Telnet("servername"); 

// start the Shell to send commands and read responses 
Shell shell = client.StartShell(); 

// set the prompt of the remote server's shell first 
shell.Prompt = "servername# "; 

// read a welcome message 
string welcome = shell.ReadAll(); 

// display welcome message 
Console.WriteLine(welcome); 

// send the 'df' command 
shell.SendCommand("df"); 

// read all response, effectively waiting for the command to end 
string response = shell.ReadAll(); 

// display the output 
Console.WriteLine("Disk usage info:"); 
Console.WriteLine(response); 

// close the shell 
shell.Close(); 
Cuestiones relacionadas