📄 telnet.java
字号:
import java.net.*;
import java.io.*;
/* Protocol : Client ----------- Server
*
* <--------- <path> (single line)
* (single line) <cmd> ---------->
* <--------- <output> (several lines)
* <--------- ==end== (single line)
*
* another session started again
*
* <--------- <path> (single line)
* .....
*/
public class Telnet {
static int port = 23;
static final String endMsg = "==end==";
public static void main(String[] args) throws Exception {
if (args[0].equals("server"))
runServer();
else if (args[0].equals("client"))
runClient(args[1], port);
else
System.out.println("Client : java Telnet client ip\r\n"+
"Server : java Telnet server");
}
public static void runClient(String host, int port) throws Exception {
System.out.println("Host " + host + "; port " + port);
Socket socket = new Socket(host, port);
new CommandClient(socket).start();
System.out.println("Connected OK");
}
public static void runServer() throws Exception {
ServerSocket server = new ServerSocket(port); //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -