Hello all,
Mau tanya nich, aku lagi buat program telnet non-aplet dengan java, tapi
saya ada kesulitan dengan pengiriman FUNCTION KEY seperti F1, F2 dst..
kira-kira gimana yach solusinya?
Begini source codenya:
import java.util.Vector;
import java.io.*;
import socket.*;
class telnet {
// create a new telnet io instance
static TelnetIO tio = new TelnetIO();
statisc String address="x.x.x.x";
static int port=5000;
// skip any received data until the prompt appears
private static void wait(String prompt)
{
String tmp = "";
do {
try { tmp = new String(tio.receive(), 0); }
catch(IOException e) { e.printStackTrace(); }
System.out.println(tmp);
} while(tmp.indexOf(prompt) == -1);
}
// send a string to the remote host, since TelnetIO needs a byte buffer
// we have to convert the string first
private static void send(String str)
{
byte[] buf = new byte[str.length()];
str.getBytes(0, str.length(), buf, 0);
try { tio.send(buf); } catch(IOException e) {}
}
// this function is called when running the class with java IOtest
// looks very much like a modem login script ;-)
public static void main(String args[])
{
try {
tio.connect(address, port);
wait("Login:");
send("<username>\r");
wait("Password:");
send("<password>\r");
wait("[Terminal Type]");
send("4410/r");
wait("Command: ");
send("<command....>\r");
send("<DISINI HARUSNYA MENGIRIM FUNCTION KEY F3>");
tio.disconnect();
} catch(IOException e) { e.printStackTrace(); }
}
}
TIA,
-danny-
--
Utk berhenti langganan, kirim email ke [EMAIL PROTECTED]
Informasi arsip di http://www.linux.or.id/milis.php3