title: How do I get the server endpoint in a running flex application?
body: <p>I need a way of getting the active server address, port, and context during runtime from my flex application.  Since we are using ant for our build process, the server connection information is dynamically specified in our build properties file, and the {server.name}, {server.port} and {context.root} placeholders are used in the services-config.xml file instead the actual values.</p>
  
  <p>We have some other Java servlets running on the same machine as our blazeDS server, and I'd like some way to programmatically determine the server endpoint information so I don't need to hardcode the servlet URL's into an XML file (which is what we are presently doing).</p>
  
  <p>I have found that I can at least get the context root by adding the following to our main application MXML file:</p>
  
  <pre><code>&lt;mx:Application ... &gt;
    &lt;mx:HTTPService id="contextRoot" rootURL="@ContextRoot()"/&gt;
  &lt;/mx:Application&gt;
  </code></pre>
  
  <p>However, I still need some way of fetching the server address and port, and if I specify the entire address by giving -context-root=<a href="http://myserver.com:8080/mycontext" rel="nofollow noreferrer">http://myserver.com:8080/mycontext</a>, then the flex application attempts to connect to <a href="http://localhost/http://myserver.com:8080/mycontext/messagebroker/amf" rel="nofollow noreferrer">http://localhost/http://myserver.com:8080/mycontext/messagebroker/amf</a>, which is of course totally wrong.  What is the proper way to specify the context root and server URL, and how can I retrieve them from our application?</p>