0

I want to try get a IP of an server (website) in the browser

I tried the following:

function transmit_game_server_if_changed() {
    if (last_transmited_game_server != window.example.ws) {
        transmit_game_server()
    }
}

function transmit_game_server() {
    last_transmited_game_server = window.example.ws;
    socket.emit("cmd", {
        "name": "connect_server",
        "ip": last_transmited_game_server
}

window.example.ws doesn't work. Is there any other way to do this?

user229044
  • 232,980
  • 40
  • 330
  • 338
mastkilxp
  • 3
  • 3

1 Answers1

1

Webbrowser APIs do not include a way to perform DNS lookups.

However, that's probably not what you want anyways - an IP can be used by multiple servers one or another, or a server could be reachable under multiple IPs (for instance IPv4 and IPv6). Instead, you can let the server generate a random value on startup, and hand that to the client. As soon as the client connects, it can determine whether it knows the server.

Community
  • 1
  • 1
phihag
  • 278,196
  • 72
  • 453
  • 469