牛骨文教育服务平台(让学习变的简单)
博文笔记

InetAddress和InetSocketAddress的区别

创建时间:2014-02-13 投稿人: 浏览次数:1945

1、InetAddress一般这样使用:其中不可以包含端口(我看文档了,这样理解是对的)。
InetAddress remoteAddr=InetAddress.getByName(“112.5.4.45″);

2、InetSocketAddress可以实现地址+端口。在需要设置连接超时时间的场合,必须使用InetSocketAddress。
Socket socket=new Socket();
SocketAddress remoteAddr=new InetSocketAddress(“localhost”,8000);
socket.connect(remoteAddr,6000);//将等待时间设置为6秒

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。