Client socket - get IP - java
问题 I am implementing a TCP connection with sockets and I need to get the IP of the client socket on the server side. I have used the socketName.getRemoteSocketAddress() which indeed returns the IP address followed by the port id I am using! how can I get just the address and not the port? 回答1: The SocketAddress that this returns is actually a protocol-dependent subclass. For internet protocols, such as TCP in your case, you can cast it to an InetSocketAddress: InetSocketAddress sockaddr =