public Socket (String dstName, int dstPort)Since: API Level 1 Creates a new streaming socket connected to the target host specified by the parameters dstName and dstPort. The socket is bound to any available port on the local host. Implementation note: this implementation tries each IP address for the given hostname until it either connects successfully or it exhausts the set. It will try both IPv4 and IPv6 addresses in the order specified by the system property "java.net.preferIPv6Addresses".注意Implementation note里面的内容,这正是你的慢的原因,可以肯定了。
恩,非常感谢,Implementation note中的exhausts the set,这个set是什么set? 另外哪里查java的api啊?
Creates a new streaming socket connected to the target host specified by the parameters dstName and dstPort. The socket is bound to any available port on the local host.
Implementation note: this implementation tries each IP address for the given hostname until it either connects successfully or it exhausts the set. It will try both IPv4 and IPv6 addresses in the order specified by the system property "java.net.preferIPv6Addresses".注意Implementation note里面的内容,这正是你的慢的原因,可以肯定了。
另外哪里查java的api啊?
甚至同一地址,所有的端口(自己使用的端口,远程端的端口不会,只会连接你指定的那个)都会试一下,这一点我也不确定。http://developer.android.com/reference/java/net/Socket.html