chenwei
asked on
How to simulate Ctrl-Break as a string?
In my program I want to send "Ctrl+Break" as a command such as "logoff" upto host. How can I do this?
What do you mean by 'upto host'?
ASKER
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.
How are you doing the telnet bit?
ASKER
It has little to do with telnet. I don't want to break up the telnet session but the program running on the host.
So you mean 'how do i stop the Java program, that i'd normally do with Ctrl-Break, programmatically?'
ASKER
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.
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
Of course you could just be brutal and close the stream. It would be preferable to send a 'quit' command first though
ASKER
the program running on the host dosen't accept "quit" but just "Ctrl+Break".
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?
>>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?
ASKER
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.getOutpu tStream();
...
try{
URL url=new URL("telnet", hostIP, port, "",
new thor.net.URLStreamHandler( ));
urlConnection=url.openConn ection();
urlConnection.connect();
if (urlConnection instanceof TelnetURLConnection) {
((TelnetURLConnection)urlC onnection) .
setTelnetTerminalHandler(n ew SimpleTelnetTerminalHandle r());
}
out=urlConnection.getOutpu tStream();
...
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 ));
}
...
http://mrl.nyu.edu/~danielk/telnet/
My program looks like:
...
private URLConnection urlConnection;
private OutputStream out;
...
out=urlConnection.getOutpu
...
try{
URL url=new URL("telnet", hostIP, port, "",
new thor.net.URLStreamHandler(
urlConnection=url.openConn
urlConnection.connect();
if (urlConnection instanceof TelnetURLConnection) {
((TelnetURLConnection)urlC
setTelnetTerminalHandler(n
}
out=urlConnection.getOutpu
...
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
}
...
Why not just call
out.close();
urlConnection.disconnect() ;
?
out.close();
urlConnection.disconnect()
?
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.