gpt4 book ai didi

java - 如何通过 Telnet 发送字符串?

转载 作者:行者123 更新时间:2023-12-01 16:57:47 26 4
gpt4 key购买 nike

我想使用 Apache 的 TelnetConnection 向 Telnet 连接发送字符串

import java.io.IOException;
import org.apache.commons.net.telnet.TelnetClient;

public class TestClass {
public static void main(String[] args) throws IOException, InterruptedException {

String telnetServer = "123.456.789.123";
int telnetPort = 32106;
TelnetClient telnet = new TelnetClient();
try {
telnet.connect(telnetServer, telnetPort);
String start = "start";
telnet.getOutputStream().write(start.getBytes());
telnet.getOutputStream().flush();

System.out.println(telnet.getInputStream());


} catch (Exception e) {
System.out.println(e);
}finally {
telnet.disconnect();
}
}
}

但是,我没有得到结果。在这种情况下如何使用输入和输出流?命令(“start”)应开始 METUS INGEST 5.6 的记录。

最佳答案

感谢一些程序员(https://stackoverflow.com/users/440558/some-programmer-dude)。这完全完成了工作。

完整代码如下:

import java.io.IOException;
import org.apache.commons.net.telnet.TelnetClient;

public class TestClass {
public static void main(String[] args) throws IOException, InterruptedException {

String telnetServer = "123.456.789.123";
int telnetPort = 32106;
TelnetClient telnet = new TelnetClient();
try {
telnet.connect(telnetServer, telnetPort);
String start = "start\r\n";
telnet.getOutputStream().write(start.getBytes());
telnet.getOutputStream().flush();

System.out.println(telnet.getInputStream());


} catch (Exception e) {
System.out.println(e);
}finally {
telnet.disconnect();
}
}
}

您可以通过以下方式停止所有源的录制:

String stop = "stop\r\n";
telnet.getOutputStream().write(stop.getBytes());
telnet.getOutputStream().flush();

关于java - 如何通过 Telnet 发送字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61559635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com