serversocket

L

lrantisi

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.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

lrantisi said:
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 have never used it, but clientSocket.getRemoteSocketAddress()
sounds relevant.

Arne
 
W

Wesley Hall

Arne said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top