socket.getInetAddress()
returns an InetAddress
object that contains the IP address of the remote machine.
InetAddress.getHostAddress()
returns a String
object with the textual representation of that address.
So, to end up with a String
you can print, that's how you do it.
Edit: In case you're not familiar, this is called 'method chaining'. It's the same thing as saying:
InetAddress addy = socket.getInetAddress();
String remoteIp = addy.getHostAddress();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…