Reputation: 417
When creating client connection to serversocket we can create client sockets in two ways My question is what is the difference between below two approaches,
InetAddress addr = InetAddress.getByName("localhost");
SocketAddress sockaddr = new InetSocketAddress(addr, 1111);
Socket clientSocket = new Socket();
clientSocket.connect(sockaddr);
And the other approach
Socket clientSocket=new Socket("localhost",1111);
What are the advantages and disadvantages
Thank you.
Upvotes: 1
Views: 1159
Reputation: 311039
They are identical.
The advantage of new Socket()
is that you can then call the other overload of connect(),
that takes a timeout parameter.
Upvotes: 1