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?

meager
  • 209,754
  • 38
  • 307
  • 315
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
  • 245,801
  • 63
  • 407
  • 443