How to get the ip of a server

Discussion in 'Plugin Development' started by Vinceguy1, Aug 5, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Vinceguy1

    I tried Bukkit.getIp().toString() and it was just a blank line.
     
  2. Offline

    Jogy34

    Bukkit.getIP() and server.getIP() return whatever is in the ip line in the server.properties file. Most of the time when hosting a server that spot is left blank so that isn't s reliable method to use.
     
    TheSmallBones likes this.
  3. Offline

    AmberK

    Could always poll an outside URL from the plugin to find it, I'm not sure about the API method.
     
  4. Offline

    Adam543i

    Best way of doing this is sending a standard http request to a PHP (or any other) script that returns the servers IP.
    PHP:
    <?php
    //echo the server ip
    echo $_SERVER["REMOTE_ADDR"];
    ?>
    I haven't really done much on HTTP requests in Java, however there is numerous tutorials on how to do so.
     
  5. Offline

    Phinary

    No, that isn't the best way. This will lag up your server if the web server is slow. Bukkit has a simple built in method to do this.
     
  6. Offline

    Adam543i

    Isn't the only method of doing this reads if from the server config (Like Jogy32 said)?
     
  7. Offline

    Phinary

    There is more efficient ways using some java method with networking to do it. It may be a bit confusing though. Try googling it.
     
  8. Offline

    Adam543i

    I just tried a few tests simulating slower web servers (by pausing the execution of the php script for x milliseconds) and I can't get the server to have any noticable lag.
    I tested it with the following wait times:
    • 0ms
    • 50ms
    • 100ms
    • 250ms
    • 500ms
    • 750ms
    • 1000ms
    However during each of the individual tests, there was no noticable lag (for players) and the tick rate was basically the same (it fluctuates a little). Of course the results would be different depending on server hardware, server load and etc.

    I did try though to simulate a server with concurrent users (3 users, doing different actions each. Those were exploring (generating chunks), breaking blocks (120 blocks per min) and killing mobs with an event listening for mob deaths then writing it to a file).

    Also these wait times were added to the average 85 ping I get to my VPS, which I had put the script that returns the ip of the server requesting it.

    A graph from the tick results with the accompanying wait times. The tick rate was taken 25ms after the request was sent (hopefully capturing any lag that would of occured).
    [​IMG]

    As you can see there is very little differences between the tick rate (it does decrease slowly, but my an extremely small margin).

    Just to clarify, I'm not stating that you're wrong by saying that it would lag out the server, as there is so many factors that could make this specific method cause the server to lag but from this specific test, I couldn't get it to lag.
     
  9. Offline

    Vinceguy1

    So there is no way of getting it?
     
  10. Offline

    Phinary

    Then what happens if your webserver goes offline, gets ddos'd etc?...
    I am not saying you are wrong, there is just much better ways to do it.
     
Thread Status:
Not open for further replies.

Share This Page