【发布时间】:2012-11-07 09:08:35
【问题描述】:
我的工作环境是我的局域网。
下面的代码示例是用 Java 语言编写的,但我的问题是关于 TCP,而不是编程。
我遇到了以下连接超时:
-
2 ms when connection established - 1 005 毫秒,当主机处于活动状态但未侦听指定套接字端口时
- 主机关闭时为 21 000 毫秒
这些值来自对我的网络的观察,但我认为它存在一个 RFC。
这里有一些关于超时的信息:
- RFC 1122
- RFC 793
- Nagle's_algorithm 和 TCP_NO_DELAY
你能给我更多的指点吗?
@Override
public void run() {
for( int port = _portFirst; port < _portLast; ++port ) {
String host = "192.168.1." + _address;
boolean success = false;
long before = System.currentTimeMillis();
try {
Socket socket = new Socket();
SocketAddress endpoint = new InetSocketAddress( host, port );
socket.connect( endpoint, 0 );
success = true;
socket.close();
}// try
catch( ConnectException c ){/**/}
catch( Throwable t ){
t.printStackTrace();
}
long duration = System.currentTimeMillis() - before;
System.err.println( host + ":" + port + " = " + duration );
_listener.hostPinged( host, port, success, duration );
}
}
【问题讨论】:
-
这些超时由您的操作系统控制,您拥有哪个操作系统/版本?
-
BTW端口扫描可以通过
nmap等现有工具轻松完成,如果可以的话我会考虑使用它。 -
谢谢,我知道nmap、lookatlan.com 或overlooksoft.com,但我的目标是获得基础知识
标签: java sockets networking tcp