Forums Register Login

how to get Client Ip address?

+Pie Number of slices to send: Send
Hello. i want to know that how can we know the ip address of client on server side in socket (java). i.e suppose there is a server "S" and 2 clients "A" and "B". Client A send me(server) some info, and Client B send me(server) some other info. i have to store that info coming from A and B in Db in different tables. How can i Differentiate between client A and B request.
+Pie Number of slices to send: Send
 

muneeb ifkaar wrote:Hello. i want to know that how can we know the ip address of client on server side in socket (java). i.e suppose there is a server "S" and 2 clients "A" and "B". Client A send me(server) some info, and Client B send me(server) some other info. i have to store that info coming from A and B in Db in different tables. How can i Differentiate between client A and B request.



Assuming that you are using TCP, your "server", which is using a ServerSocket should return different Socket objects for each client, and hence, should be easy for you to differentiate the two clients.

However, to answer you question -- with the data Socket object, you can get the InetAddress object, which can be used to get the IP address. A word of warning though, this address may be incorrect if the clients are going through a firewall or router that is going through network address translation.

Henry
+Pie Number of slices to send: Send
can you please write a sample code for me

Thanks
+Pie Number of slices to send: Send
 

muneeb ifkaar wrote:can you please write a sample code for me


The Ranch is NotACodeMill
Did you take a look at the API for the class which Henry recommended? Do you see any method there which might help you?
+Pie Number of slices to send: Send
yeah i'did. i find some methods whic i think is helpful for me, ie. getHostAdrress() , getByname(), getByAddress(), but i dont know know how to use these methods to get my desired result.
+Pie Number of slices to send: Send
 

muneeb ifkaar wrote:...but i dont know know how to use these methods.



Static methods can be invoked with its "classname dot method name". For ex. almost all methods in Math class are static, i.e. you can invoke them using "Math.methodName()"

Non-static method require an object before you can place a dot (.) to invoke them.

If method signature has parameters, then calling it requires proper arguments to be passed in its call statement.
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3358 times.
Similar Threads
IP Address Sniffer Log
Alert Message in B&S
HTTP push
about properties.txt problem
How to get IP Address for the Client
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:21:06.