gpt4 book ai didi

java - Android发送套接字: What is the difference between these two methods for initializing a socket?

转载 作者:行者123 更新时间:2023-11-29 22:05:50 25 4
gpt4 key购买 nike

方法一:

InetAddress addr = InetAddress.getByName("192.168.0.101");
int port = 18250;
Socket socket = new Socket(addr, port);

方法二:

Socket socket = new Socket("192.168.0.101",18250);

最佳答案

它们是一样的:

Java 源代码:

public
class Socket {

...

public Socket(String host, int port)
throws UnknownHostException, IOException
{
this(host != null ? new InetSocketAddress(host, port) :
new InetSocketAddress(InetAddress.getByName(null), port),
(SocketAddress) null, true);
}


public Socket(InetAddress address, int port) throws IOException {
this(address != null ? new InetSocketAddress(address, port) : null,
(SocketAddress) null, true);
}

...
}

关于java - Android发送套接字: What is the difference between these two methods for initializing a socket?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10780815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com