• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get the IP Address

 
Mike Abayon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to get the IP address of a client computer that just connected to the server?
 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mike,
what is the method you are using for the connection between the client and the server?
If you are using TCP then use the Socket that you get from ServerSocket.accept().
Socket.getInetAddress() will give the InetAddress object.
You can use InetAddress.getHostAddress() to get a string representation of the IP Address. You can look at the InetAddress class documentation for other useful methods.
If you are using UDP then use the DatagramPacket object you received.
The DatagramPacke.getAddress() will also return an InetAddress object.
Regards,
Amit
 
Mike Abayon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit!
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the informations!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic