Search code examples
javasocketsserverclientexternal

Java socket: Get clients external IP


I've built a client server application. How can I get the client IP on the serverside? I already used "socket.getRemoteSocketAddress()" but this gives an internal IP.


Solution

  • When you start to listen with serverSocket.accept(); and you store the Socket returning object of this function, you can get the client ip with this function from the socket with this: socket.getInetAddress().getHostAddress();.