Solved

How to simulate  Ctrl-Break as a string?

Posted on 2004-09-15
16
385 Views
Last Modified: 2008-03-03
In my program I want to send "Ctrl+Break" as a command such as "logoff" upto host. How can I do this?
0
Comment
Question by:chenwei
  • 8
  • 6
16 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12063406
What do you mean by 'upto host'?
0
 

Author Comment

by:chenwei
ID: 12063478
I set up a telenet session and break up the program on host. Normally I can use Ctrl+Break to do this if I use directly the host. Now I have to simulate this "Ctrl+Break" and send upto the host.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12063500
How are you doing the telnet bit?
0
 

Author Comment

by:chenwei
ID: 12063541
It has little to do with telnet. I don't want to break up the telnet session but the program running on the host.

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12063563
So you mean 'how do i stop the Java program, that i'd normally do with Ctrl-Break, programmatically?'
0
 

Author Comment

by:chenwei
ID: 12063678
No. I used java Swing to program a Telnet-GUI. I use this GUI to send commans via telnet to run the program on host. Now I want to break up the program. So I have to send a command of "Ctrl+Break" via telnet to the host.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12063700
Why in that case do you say 'It has little to do with telnet'? It seems to me to have everything to do with telnet. You need to send whatever the quit command is in telnet
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:CEHJ
ID: 12063812
Of course you could just be brutal and close the stream. It would be preferable to send a 'quit' command first though
0
 

Author Comment

by:chenwei
ID: 12063881
the program running on the host dosen't accept "quit" but just "Ctrl+Break".
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12063929
There is no command 'quit' in telnet of course.

>>I use this GUI to send commans via telnet to run the program on host

Can you tell me exactly how the telnet bit of the above is being done?
0
 

Author Comment

by:chenwei
ID: 12064076
I use the Thor Telnet Classes to do the telnet connection:
http://mrl.nyu.edu/~danielk/telnet/

My program looks like:
...
private URLConnection urlConnection;
private OutputStream out;
...
out=urlConnection.getOutputStream();
...

try{
 URL url=new URL("telnet", hostIP, port, "",
  new thor.net.URLStreamHandler());
  urlConnection=url.openConnection();
  urlConnection.connect();
  if (urlConnection instanceof TelnetURLConnection) {
      ((TelnetURLConnection)urlConnection).
      setTelnetTerminalHandler(new SimpleTelnetTerminalHandler());
  }
 out=urlConnection.getOutputStream();
...

If I send a command upto host via telnet, I call this function:
...
for(int i = 0; i< command.length(); i++)
{
  out.write(command.charAt(i));
}
...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12064249
Why not just call

out.close();
urlConnection.disconnect();

?
0
 

Author Comment

by:chenwei
ID: 12064332
out.close() will close the telnet session or something similar. But I have to stop or break up the program, for example an editor, running on the host first.

Besides, if I break up the program running on the host doese't mean I will close the telnet session. I wan to do something else on the host.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 20 total points
ID: 12064402
You need to tell it to stop. I don't know the telnet protocol, but this looks promising:

http://mrl.nyu.edu/~danielk/telnet/docs/thor/net/TelnetConstants.html#AO

You could maybe mail the author
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 32
table example 4 24
How to convert String matching to regex in java 4 21
type mismatch (Object[] to double[] 4 10
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now