Re: Using port 23 and issuing telnet commands...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

It may be the encoding

Do you need the response you are getting from the host?
if not just discard it

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Rex Winn" <rex@xxxxxxxxxxxxx> wrote in message
news:151693632506376628281250@xxxxxxxxxxxxxxxxxxxxxxx
> So I have adapted your code and it's working well enough. I think
> that I'm the weak link. This is my first time writing socket level
> code and working with bytes and streams so I am defitely new to
> it. When I establish a connection in telnet this is the screen I get
> immediately:
> {OUTPUT TEXT - Telnet Console}
> +-------------------------------------------------+
> |+-----------------------------------------------+|
> || ||
> || DIRECWAY 6000 VSAT ||
> || ||
> || Install Console ||
> || ||
> || Dec 7 2004, 13:42:17 ||
> || ||
> || Copyright (c) 2004 Hughes Network Systems ||
> |+-----------------------------------------------+|
> +-------------------------------------------------+
>
>
>
>
>
> Time of Reset : THU APR 07 09:31:08 2005
> Asserted at : t=tMct /cm_data/brighton/source/usr_s2.c#403:
> Reset Type : Valid Software Reset
> Reset Reason : Unexpected VxWorks Exception
>
>
> Main Menu (<?/CR> for options):
> {/OUTPUT TEXT}
>
> Now this is exactly 1010 bytes. However when using the code you gave me.
> This is all the text I get.
>
> {OUTPUT TEXT - Debugger}
> "\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r
> +-------------------------------------------------+\n\r
> |+-----------------------------------------------+|\n\r || ||\n\r
> || DIRECWAY
> {OUTPUT TEXT}
>
> This is 259 bytes in length.
> Why am I not getting all the output? How can I get it? I've sized the
> buffer
> to huge and still don't get it. Ideas?
>
> Here's the modified code:
>
> using System;
> using System.Text;
> using System.Net.Sockets;
> using System.IO;
>
> namespace SigStrength
> {
> /// <summary>
> /// /// </summary>
> public class satTelnet
> {
> public satTelnet()
> {
> // // TODO: Add constructor logic here
> //
> }
> public bool Connect(string Command, string Host, int Port,string
> cmdQuestionMark, string cmdC, string cmdG)
>
> {
> // telnet 192.168.0.1 1953
> // ?
> // c
> // g
> // repeat g
> // z - return to main menu
> // z - logout
>
> TcpClient client = null;
>
> byte[] read = new byte[1024];
>
> byte[] send = new byte[1024];
>
> int bytes;
>
> string data;
>
> try
>
> {
>
> client = new TcpClient(Host,Port);
>
> }
>
> catch (Exception ex) //connection problem
>
> {
>
> throw ex;
>
> }
>
> NetworkStream stream = client.GetStream();
> send = Encoding.ASCII.GetBytes(cmdQuestionMark);
>
> stream.Write(send,0,send.Length);
>
> bytes = stream.Read(read, 0, read.Length);
>
> data = Encoding.ASCII.GetString(read);
> System.Diagnostics.Debug.WriteLine(data); //- DEBUG PRINT
> send = Encoding.ASCII.GetBytes(cmdC);
>
> stream.Write(send,0,send.Length);
>
> bytes = stream.Read(read, 0, read.Length);
>
> data = Encoding.ASCII.GetString(read);
> System.Diagnostics.Debug.WriteLine(data); //- DEBUG PRINT
> send = Encoding.ASCII.GetBytes(Command);
>
> stream.Write(send,0,send.Length);
>
> bytes = stream.Read(read, 0, read.Length);
>
> data = Encoding.ASCII.GetString(read);
> System.Diagnostics.Debug.WriteLine(data); //- DEBUG PRINT
> string retval = Encoding.ASCII.GetString(read);
>
> stream.Close();
>
> client.Close();
>
> if (retval[0]=='0')
>
> return true;
>
> else
>
> return false;
>
> }
>
>
> }
> }
>
>
>
>
>
>


.



Relevant Pages