Question

I have a question regarding the embedding of a GWT application.

The problem concerns getting the address of the client, and match it to the ip in the tag's src attribute. So the structure is Host html page (hosted on server a), embedding a gwt application hosted on server b.

    <!DOCTYPE HTML>
<html dir="ltr" lang="en-US">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

   <title>Embedding gwt app</title>
   <script type="text/javascript" src="http://192.168.0.1:8080/myapp/myapp.nocache.js?rootpanel=divone"></script>
 </head>
 <body>
    <div id="divone" style="width:100px;height:100px;"></div>   
 </body>
</html>

What we have tried before is get the host path by using GWT.getHostPageBaseURL(), but this returns the host page's ip (we expected this..)

Are we trying to achieve something impossible? considering that the script file gets downloaded first, and then the onModuleLoad gets called when the script is ready on the client.

Was it helpful?

Solution

You can make a RPC request to the server side, and the server can do the following to get the client's IP: getThreadLocalRequest().getRemoteAddr();

Or if you don't want to make a request and want to do the work on the client side, you can make a GWT native JS method and try one of the suggestions from this stackoverflow post: How to get client's IP address using javascript only?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top