Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Telnet Clear Screen?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pbd22 - 18 Jan 2008 19:04 GMT
Hi.

Does anybody know how to issue a clear screen command like DOS "cls"
in a telnet session?

Thanks!
Ignacio Machin ( .NET/ C# MVP ) - 18 Jan 2008 19:30 GMT
Hi,

IIRC it does depend of what terminal is being emulated. Some terminals do
not allow it.
Of course you can always emit X (20?) empty rows and that will clean it.
Signature

Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

> Hi.
>
> Does anybody know how to issue a clear screen command like DOS "cls"
> in a telnet session?
>
> Thanks!
zacks@construction-imaging.com - 18 Jan 2008 20:16 GMT
> Hi.
>
> Does anybody know how to issue a clear screen command like DOS "cls"
> in a telnet session?
>
> Thanks!

Like Ignacio says, it depends on the terminal being emulated. For the
old DEC VT style terminals, there is an "escape sequence" that when
sent to the terminal would clear the screen, <ESC>[2J.
pbd22 - 18 Jan 2008 21:27 GMT
> Like Ignacio says, it depends on the terminal being emulated. For the
> old DEC VT style terminals, there is an "escape sequence" that when
> sent to the terminal would clear the screen, <ESC>[2J.

Thanks guys.

Well, I have written a telnet server in C# that captures the port 23
connection and uses TcpClient to read/write to interact with the
user's DOS console.

So, I am a little confused. Should I be sending these commands
as such:

               buffer = ASCII.GetBytes("<ESC>[2j");
               _clientStream.Write(buffer, 0, buffer.Length);
               _clientStream.Flush();

Well, I will give it a shot (correct me if I am wrong).

Thanks!
Peter Duniho - 18 Jan 2008 22:50 GMT
> [...]
> So, I am a little confused. Should I be sending these commands
[quoted text clipped - 3 lines]
>                 _clientStream.Write(buffer, 0, buffer.Length);
>                 _clientStream.Flush();

That will only work if the other end has a terminal emulator that is  
acting as a VT-series terminal (or at least as some terminal that uses the  
same control codes).  In other words, it might work but it's not something  
you can count on.

You seem to be confusing the user terminal with telnet.  Telnet is not  
terminal emulation, and doesn't really have anything to do with terminal  
emulation.  You may want to layer some additional protocol above the  
telnet protocol, to support things like character formatting and screen  
clearing, but you should not expect the remote end to support those  
things.  A telnet client can be fully functional without having _any_ sort  
of graphical control over the display.

Which is not to say that the telnet protocol doesn't support escape  
codes.  It does, and your server should be aware of these and handle them  
properly.  See the actual telnet specification for details:  
http://www.faqs.org/rfcs/rfc854.html

Unless your server fully conforms to the specification, you don't actually  
have a telnet server.

Pete
Arne Vajhøj - 19 Jan 2008 01:42 GMT
> Well, I have written a telnet server in C# that captures the port 23
> connection and uses TcpClient to read/write to interact with the
[quoted text clipped - 8 lines]
>
> Well, I will give it a shot (correct me if I am wrong).

Whether the concept will work or not in your context I dont't know.

It should work if the C# program is running on the remote system
and outputs to a terminal emulator emulating VT200 or higher.

Like running the app with mono on a Linux box.

But one little thing "<ESC>[2j" will not work - instead use
"\u001B[2J".

<ESC> is a single char. And it is uppercase J.

Arne
christery@gmail.com - 20 Jan 2008 01:30 GMT
> But one little thing "<ESC>[2j" will not work - instead use
> "\u001B[2J".

Jepp, esc =ascii 27 and that (<ESC>) might not work ;)
if you dont know what terminal is connected.. 50 lines of CR/LF or
just LF?
google for ANSI-BBS terminal would be a sugestion...
as I alway said "Who stole chr$(12)" of FF as someone called it... try
that..
pbd22 - 21 Jan 2008 04:09 GMT
> > Well, I have written a telnet server in C# that captures the port 23
> > connection and uses TcpClient to read/write to interact with the
[quoted text clipped - 22 lines]
>
> Arne

Thanks all.

Arne - that worked, sort of.
It cleared the screen (thanks) but each time a function clears the
screen the space
at the top gets bigger. It seems that something that I can't see is
getting
written and gets built upon the next time the clear statement fires.

Also, what exactly is the \u? Is there a way that I can find out what
other commands
I have at my disposal in the same format as the one you just provided
(ie. \u plus
something).

Thanks again!
Peter
Arne Vajhøj - 21 Jan 2008 04:26 GMT
>> It should work if the C# program is running on the remote system
>> and outputs to a terminal emulator emulating VT200 or higher.
[quoted text clipped - 5 lines]
>>
>> <ESC> is a single char. And it is uppercase J.

> It cleared the screen (thanks) but each time a function clears the
> screen the space
> at the top gets bigger. It seems that something that I can't see is
> getting
> written and gets built upon the next time the clear statement fires.

Very difficult to troubleshoot. What terminal emulator ? What terminal
does it emulate ? What space is getting bigger ?

> Also, what exactly is the \u? Is there a way that I can find out what
> other commands
> I have at my disposal in the same format as the one you just provided
> (ie. \u plus
> something).

\u001B means the unicode character 27 (1B in hex is 27 in decimal).

If the terminal is ANSI or VT100 or VT200 compatible there
are a bunch of socalled escape sequences you can use.

Try google for "VT100 escape sequence" or "VT200 escape sequence" - you
will get plenty of hits.

Arne
christery@gmail.com - 26 Jan 2008 22:10 GMT
> > It cleared the screen (thanks) but each time a function clears the
> > screen the space
> > at the top gets bigger. It seems that something that I can't see is

It grows, its going to kill us all... run... the space is coming..
THE SPACE stole chr$(12)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.