Why does Socket.getHostOrIP() return localhost ?

23 views
Skip to first unread message

Gareth Murfin

unread,
Sep 20, 2016, 2:08:48 PM9/20/16
to CodenameOne Discussions
Socket.getHostOrIP() returns localhost andn ot an ip, why is that ??

Shai Almog

unread,
Sep 21, 2016, 12:47:36 AM9/21/16
to CodenameOne Discussions
On which OS?
Notice that getting the current host/IP is problematic.

Gareth Murfin

unread,
Sep 21, 2016, 2:10:59 PM9/21/16
to CodenameOne Discussions
on Android..  is it problematic? I saw some native code for android that claims to work, not tried yet. My client wishes to identify which country the user is in via their ip (some sort of traceroute I assume) - that is why we need the ip. I guess I could visit whatsmyip.com and scrape it somehow.

On 21 September 2016 at 05:47, Shai Almog <shai....@gmail.com> wrote:
On which OS?
Notice that getting the current host/IP is problematic.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/myQHUlgkm7c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/2548ff0c-494c-4c57-a3cc-fe5c5811231c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Gareth Murfin
(Android Freelancer - www.garethmurfin.co.uk)

Shai Almog

unread,
Sep 21, 2016, 11:49:49 PM9/21/16
to CodenameOne Discussions
This is usually done on the server side where it is more reliable as the IP might be 192.168.* which will give you nothing.

Gareth Murfin

unread,
Sep 22, 2016, 2:39:26 PM9/22/16
to CodenameOne Discussions
how could it be done on the server side though? I want the IP of the client, I dont see how the server could work it out ?

On 22 September 2016 at 04:49, Shai Almog <shai....@gmail.com> wrote:
This is usually done on the server side where it is more reliable as the IP might be 192.168.* which will give you nothing.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/myQHUlgkm7c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.

For more options, visit https://groups.google.com/d/optout.

Dave Dyer

unread,
Sep 22, 2016, 4:26:36 PM9/22/16
to CodenameOne Discussions

A client on any kind of LAN will return 192.168.0.n or something equally useless.   The only
way to find what IP the host presents to the outside world is to be in the outside world.

Shai Almog

unread,
Sep 23, 2016, 2:04:01 AM9/23/16
to CodenameOne Discussions
This is pretty easy to do in the servlet API thru the HttpServletRequest class.

Gareth Murfin

unread,
Sep 24, 2016, 9:15:16 PM9/24/16
to CodenameOne Discussions
Ah a good old servlet, cheers!!

On 23 September 2016 at 07:04, Shai Almog <shai....@gmail.com> wrote:
This is pretty easy to do in the servlet API thru the HttpServletRequest class.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/myQHUlgkm7c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages