I am using the serversocket.
When a request arrives, I do the following.
Socket clientSocket = listenSocket.accept();
Now how can I use the clientSocket to know the IP address of the client
that sent that request.
> I am using the serversocket.
> When a request arrives, I do the following.
[quoted text clipped - 3 lines]
> Now how can I use the clientSocket to know the IP address of the client
> that sent that request.
I have never used it, but clientSocket.getRemoteSocketAddress()
sounds relevant.
Arne
Wesley Hall - 25 Nov 2006 01:03 GMT
>> I am using the serversocket.
>> When a request arrives, I do the following.
[quoted text clipped - 6 lines]
> I have never used it, but clientSocket.getRemoteSocketAddress()
> sounds relevant.
You have to do a little more if you want the remote endpoint in string
form...
String remoteIP =
((InetSocketAddress)clientSocket.getRemoteSocketAddress()).getAddress().toString()
...that should do it. Just need to bare in mind that if the socket is
not connected then this will throw a NullPointerException as
.getRemoteSocketAddress() will return null.