• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to get Client Ip address?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
muneeb ifkaar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you please write a sample code for me

Thanks
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
muneeb ifkaar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic