The difference between passing in the InetAddress object and passing in the address to construct the socket object

  Kiến thức lập trình

enter image description here
enter image description here
When I use Socket socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 16249); in Client to construct the socket,I can successfully get the “hello, client” sent by the server to me, as well as the number of characters 12.
But when I use Socket socket = new Socket(InetAddress.getLocalHost(), 16249); to construct the socket.The server program can successfully obtain the data sent from the client, but the client falls into a loop at while(i==0)

I want to know the difference between the two construction methods

I also want to know what caused the other construction method to fail to enable the client to receive the data sent from the server

New contributor

shuaige da is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT