简体   繁体   English

通过telnet连接时发生连接超时

[英]Connection timeout occurs while connecting through telnet

I am writing a telnetclient example using apache-commons-net.2.0.jar to connect to a target using telnet protocol. 我正在使用apache-commons-net.2.0.jar编写telnetclient示例,以使用telnet协议连接到目标。 There is no problem with the jar it establishes the connection with the host if the host is up and running. 如果主机已启动并正在运行,则jar可以建立与主机的连接,这是没有问题的。 If i reboot the system and tries to connect to the host telnetclient is throwing Connection time out Exception. 如果我重新启动系统并尝试连接到主机telnetclient,则会抛出连接超时异常。

telnetClient.setConnectionTimoeout(180 * 1000) --> setting 180 seconds connection timeout telnetClient.setDefaultTimoeout(180 * 1000) telnetClient.setConnectionTimoeout(180 * 1000)->设置180秒的连接超时telnetClient.setDefaultTimoeout(180 * 1000)

Telnet client is not waiting upto 180 seconds. Telnet客户端最长不等待180秒。 It throws connection timeout exception after 30 seconds(approximately). 30秒(大约)后,它将引发连接超时异常。 I tried the example with commons-net-3.0.jar and getting the same exception. 我尝试了commons-net-3.0.jar的示例,并得到了相同的异常。 As per my understanding setConnectionTimeout should wait upto 180 seconds if the host is not up. 根据我的理解,如果主机没有启动,setConnectionTimeout应该等待长达180秒。

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

class TelnetClientExample
{
    public static void main(String[] args)
    {
    System.out.println("Started");
        TelnetClient telnet;
        telnet = new TelnetClient();
        try
        {
            telnet.setConnectTimeout(1800000);
        telnet.setDefaultTimeout(1800000);
        telnet.connect(InetAddress.getByName("hostname"),23);
            //telnet.connect("ipaddress", 23);
        System.out.println("Connected");

        }
        catch (IOException e)
        {
            e.printStackTrace();
        System.out.println("Connection timeout = "+telnet.getConnectTimeout());
            System.exit(1);
        }
    try
        {
            telnet.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
        }
        System.exit(0);
    }
}

Error: 错误:

Started
java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:182)
    at TelnetClientExample.main(TelnetClientExample.java:17)

Thanks in Advance.. 提前致谢..

You can't increase a TCP connection timeout beyond the platform default (of about a minute) by any means. 任何方式都不能使TCP连接超时超过平台默认值(大约一分钟)。 You can only decrease it. 您只能减少它。 Contrary to what the Javadoc says in several places, a zero connect timeout doesn't mean infinity, it means the platform default. 与Javadoc在几个地方所说的相反,零连接超时并不意味着无穷大,这意味着平台是默认的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 telnet 连接到外部数据库 - Connecting to external database through telnet Android:连接到本地主机上的服务器时设备上的连接超时 - Android: Connection timeout on device while connecting to the server on localhost ConnectException:连接被拒绝(连接被拒绝) - 通过Jedis连接到Redis - ConnectException: Connection refused (Connection refused)- While connecting to Redis through Jedis 通过JDBC连接PostgreSQL数据库时出现连接问题 - Connection problem while connecting to PostgreSQL database through JDBC 如何通过串行端口创建telnet连接? - How to create a telnet connection through Serial port? 如何找出客户端通过telnet连接到我的服务器? - How to find out client is connecting to my server through telnet? 连接到远程Postgresql数据库时的连接超时 - connection timeout when connecting to a remote postgresql database 如何证明套接字连接超时在60秒内发生? - How to prove that the socket connection timeout occurs within 60 seconds? java.net.ConnectException:通过代理连接时连接超时 - java.net.ConnectException: Connection timed out while connecting through a proxy 通过Java代码连接到MicroSoft Sql Server 2012时出现连接错误 - Connection error while Connecting to MicroSoft Sql Server 2012 through Java Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM