How to: get server IP?

Hello guys,

I need to get server IP to store in the database. Is it possible?

Server - the server where I launch my wowza application.

Flash/Flex applications can get data from server-pages, which connect to the database. So it is indirect. It’s not difficult but we don’t have any guidance on that here. In Flash the simple method is Loadvars. Flex adds the HTTPService.

Wowza modules can connect to a database directly using JDBC, but I don’t think you want that in this context.

Richard

Take a look at this howto:

http://www.rgagnon.com/javadetails/java-0390.html

Richard

Further info: It’s not possible, because it is too late in onAppStart to do what you want to do, and there is not another way.

Richard

Okay, great. So all you need was to know what it is, not change it. That is good.

Richard

Just to add some more value to an old thread… one can use the following to get the public ip of a server if it’s NAT’d.

    private String getPublicServerIP()
    {
        String ip = null; //you get the IP as a String
        try
        {
            URL myip = new URL("http://checkip.amazonaws.com/");
            BufferedReader in = new BufferedReader(new InputStreamReader(myip.openStream()));
            ip = in.readLine();
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return ip;
    }

Thanks,

Jake

Hello Richard,

Thank you very much for your answer. The problem is that I need to determinate server IP in the onAppStart function. Server IP which hosts application. Now I do it manually using Application.xml properties. But I need to manually set correct IP for each server instance that is not good and I’m looking for way to determinate the IP automatically in function onAppStart.

Hello Richard,

Thank you again for your help. I did so:

	private String getServerIP() {
		try {
			InetAddress address = InetAddress.getLocalHost();
			return address.getHostAddress();
		} catch( Exception error ) {
			getLogger().error( "getServerIP() error" );
		}
		return "127.0.0.1";
	}

And I call this function like:

public void onAppStart( IApplicationInstance instance ) {
	String ip = getServerIP();
	long roomIP = Strings.IpToLong( ip );

It works properly, i.e. I get server IP.

Thanks,

D