简体   繁体   English

打开一个Java套接字与Telnet?

[英]opening a Java socket vs. Telnet?

If I execute the following code (NOTE: not the real IP address being used) 如果我执行以下代码(注意:不是正在使用的真实IP地址)

Socket s = new Socket("120.200.100.111", 80);
s.setSoTimeout(10 * 1000);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
in.readLine();

After 10 seconds, I get 'SocketTimeoutException: Read timed out' 10秒后,我收到“ SocketTimeoutException:读取超时”

But if I telnet, I get: 但是,如果我远程登录,则会得到:

telnet> open 120.200.100.111 80
Trying 120.200.100.111...
Connected to foo.bar.org.
Escape character is '^]'.

Please note I am aware that for a full application I should use some sort of existing API for socket communications, but shouldn't the above test be getting some sort of timely response from the server? 请注意,我知道对于完整的应用程序,我应该使用某种现有的API进行套接字通信,但是上面的测试不应该从服务器获得某种及时的响应吗?

shouldn't the above test be getting some sort of timely response from the server? 上面的测试是否应该从服务器获得某种及时的响应?

No. A Telnet exchange doesn't start with the server sending you anything. 否。Telnet交换不是从服务器向您发送任何内容开始的。 You have to send something. 必须发送一些东西。 The server is waiting for you; 服务器正在等待您; you are waiting for it; 您正在等待; you're the one with the read timeout, so you get a read timeout. 您就是读取超时的人,因此您获得了读取超时。

The Telnet client doesn't use read timeouts by default. Telnet客户端默认不使用读取超时。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM