1

How to get clients IP address in gwt I tried using this

String ip = InetAddress.getLocalHost()+"";

when i run on local i get proper IP address of my machine but when i deployed it on server i got 127.0.0.1 which is ip address of my development mode link so how can i get client machine's IP address from server.

i also tried using

String ip = getThreadLocalRequest().getRemoteAddr();

it showed the ip address of server but not clients machine ...

Any help ....thanks in advance

stickfigure
  • 13,458
  • 5
  • 34
  • 50
  • Are you want to fetch that address from client or server code? I get confused here, you want to get client adress from server code, is that correct? – Dawid Pura Jul 16 '15 at 12:24
  • 1
    `getThreadLocalRequest().getRemoteAddr();` should work. – geert3 Jul 16 '15 at 12:33
  • Yes i want to get client ip address from server code i tried using this getThreadLocalRequest().getRemoteAddr(); but it shows ip address of server and not the client machine – Rohan Bhagde Jul 16 '15 at 13:09
  • 1
    @RohanBhagde it works when deployed..just try it – Tobika Jul 17 '15 at 07:26

1 Answers1

-2

My understanding, GWT is not able to get client IP address, because it is compiled into JS, which has no ability to do that. However there is some ways to get IP in the client side, such as applet and flash. and then they could handle the IP address into JS. GWT could make use of JSNI to work with, like applet to get the IP.

user1484819
  • 899
  • 1
  • 7
  • 18
  • That is not correct. The method getThreadLocalRequest is defined in the AbstractRemoteServiceServlet class, which belongs to the gwt framework. Also the servlet classes (often ending with Impl), which are handling the RPCs, extend the RemoteServiceServlet, which is also a class of the gwt framework. And when handling RPCs its not a hard task to get the IP of the client. – Akkusativobjekt Jul 17 '15 at 08:38
  • using javascript has nothing to do with a client making a request to a server and the server knowing where it's coming from – vinnyjames Feb 14 '18 at 19:22