C sharp - enter automatico

 
Vista:

enter automatico

Publicado por israel (3 intervenciones) el 22/01/2008 01:08:33
estoy desarrollando una aplicacion en c# la cual debe de conectarse de manera automatica a un servidor via telnet pero tengo un problema ya que el servidor no cuenta con nombre de usuario ni password solo le deberia de dar enter para que me deje continuar pero cuando me pide el nombre de usuario no se como pasarle un enter de manera automatica y esto me es de gran necesidada ya que la aplicacion se ejecutara a diversas horas de manera automatica les dejo mi codigo y de ante mano se los agradesco

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Collections;
namespace TelnetConnection
{
public partial class TelnetConnection : Form
{
public TelnetConnection()
{
InitializeComponent();
}
private void salir_Click(object sender, EventArgs e)
{
Close();
}
private void aceptar_Click(object sender, System.EventArgs e)
{
try
{
TcpClient telnet = new TcpClient("127.0.0.1", 23);
NetworkStream telnetStream = telnet.GetStream();
StreamWriter input = new StreamWriter(telnetStream);
StreamReader output = new StreamReader(telnetStream);
string str;
str = output.ReadLine();
conexion.Text = "* CONECTADO: " + str + " * ";

//VERIFICO SI PUEDO ESCRIBIR EN EL SERVER
try
{
if (telnetStream.CanWrite)
{
System.Windows.Forms.Keys enter = Keys.Enter;

Byte[] sendBytes = Encoding.Unicode.GetBytes(" -".Replace("-", ""+enter+""));
telnetStream.Write(sendBytes, 0, sendBytes.Length);
SendKeys.Send("{tab}");
SendKeys.Send("+{enter}");

/*
byte[] WriteBufferD = Encoding.ASCII.GetBytes(" ".Replace("xFF", "x0D"));
telnetStream.Write(WriteBufferD, 0, WriteBufferD.Length);*/
conexion.Text = "* ESCRITURA PERMITIDA: " + telnetStream.CanWrite + " * ";
}
else
{
conexion.Text = "* ESCRITURA DENEGADA: " + telnetStream.CanWrite + " * ";
}
}
catch
{
conexion.Text = "* NO SE PUEDE ESCRIBIR EN EL SERVER *";
}
//VERIFICO LA RESPUESTA DEL SERVER
try
{
if (telnetStream.CanRead)
{
byte[] ReadBuffer = new byte[8192];
StringBuilder CompleteMessage = new StringBuilder();
int numberOfBytesRead = 0;
StreamReader outputt = new StreamReader(telnetStream);
string strr;
strr = outputt.ReadLine();
// RESPUESTA DEL SERVER ESTA PUEDE SER MAS GRANDE QUE EL BUFFER
do
{
numberOfBytesRead = telnetStream.Read(ReadBuffer, 0, ReadBuffer.Length);
CompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(ReadBuffer, 0, numberOfBytesRead));
}
while (telnetStream.DataAvailable);
// RESPUESTA DEL SERVER
conexion.Text = "* RESPUESTA SERVER: " + CompleteMessage + " * ";
}
else
{
conexion.Text = "* NO SE PUEDE LEER DEL SERVER * ";
}
}
catch (SocketException ex)
{
conexion.Text = "* NO SE PUEDE LEER DEL SERVER " + ex + " * ";
}
}
catch (SocketException ex)
{
conexion.Text = "* LA CONEXION FALLO: " + ex+" * ";
}
}//BOTON aceptar_Click
private void userName_Enter(object sender, System.EventArgs e)
{
//Control ctrl = sender as Control;
//this.conexion.Text = "El control con el foco es: " + ctrl.Name;
SendKeys.Send("{tab}");
}
private void password_TextChanged(object sender, EventArgs e)
{
}
}//CLASE TelnetConnection
}//namespace TelnetConnection
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:enter automatico

Publicado por CASTELL01 (1 intervención) el 20/06/2008 20:07:06
HOLA CREO QUE LO PUEDES RESOLVER CONLOCANDO AL FINAL DE LA INSTRUCCION esto hace el efecto del enter a mi me funciono en java exitos saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar