?? telnetclient.java
字號:
import java.net.*;
import java.io.*;
public class TelnetClient {
String host="162.105.31.222"; //Telnet服務器地址
int port=23; //端口號
public TelnetClient() {
System.out.println("Host " + host + "; port " + port);
try {
Socket socket = new Socket(host, port); //實例化套接字
new Listener(socket.getInputStream(), System.out).start(); //輸出服務器信息到控制臺
new Listener(System.in, socket.getOutputStream()).start(); //輸出控制臺信息到服務器
} catch(IOException ex) {
ex.printStackTrace(); //輸出錯誤信息
return;
}
System.out.println("Connected Success");
}
class Listener extends Thread {
BufferedReader reader; //輸入流
PrintStream ps; //輸出流
Listener(InputStream is, OutputStream os) {
reader = new BufferedReader(new InputStreamReader(is)); //實例化輸入流
ps = new PrintStream(os); //實例化輸出流
}
public void run() {
String line;
try {
while ((line = reader.readLine()) != null) { //讀取數據
ps.print(line); //輸出數據
ps.print("\r\n");
ps.flush();
}
} catch(IOException ex) {
ex.printStackTrace();
}
}
}
public static void main(String[] argv) {
new TelnetClient();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -