| host_name$ - the machine name to look up, e.g. "www.example.com" or "localhost"; a dotted address such as "127.0.0.1" also works |
|
Looks up a host name and returns how many IP addresses it has. This is your way from a human-friendly server name to the packed integer addresses the UDP commands need. The lookup's results are stored for you: read each one with HostIP, using indexes 1 up to the count this command returned, and format them with DottedIP. Busy names can genuinely have several addresses; a home machine name or "localhost" typically has one. Returns 0 if the name could not be resolved - a typo, or simply no network - so a game can fail politely with a "server not found" message instead of crashing. Each call replaces the previous results, so finish reading one lookup's HostIP list before starting another. The call blocks until the lookup completes. "localhost" and dotted addresses answer instantly (no network needed), but a real name asks the DNS servers and can take a noticeable moment - occasionally seconds when the network is slow to say no. Resolve at load time or behind a "connecting..." screen, never in the middle of a game loop. See also: HostIP, DottedIP, OpenTCPStream, CreateUDPStream. |
; CountHostIPs Example
; --------------------
; CountHostIPs looks up a host name and returns how many IP
; addresses it has - "localhost" resolves even with no internet.
; The call blocks until the lookup finishes, so do it at load
; time rather than in the middle of a game loop.
count=CountHostIPs("localhost")
Print "CountHostIPs('localhost') = "+count
; The addresses it found are read back with HostIP, indexed
; from 1 to the returned count
For i=1 To count
Print " address "+i+": "+DottedIP$(HostIP(i))
Next
; A dotted address works too - it 'resolves' to itself
count=CountHostIPs("127.0.0.1")
Print "CountHostIPs('127.0.0.1') = "+count
; An unknown name returns 0, so a game can fail gracefully
count=CountHostIPs("no-such-host.invalid")
Print "CountHostIPs('no-such-host.invalid') = "+count
If count=0 Then Print " (name not found - no server to join)"
Print ""
Print "Press any key to close the example"
WaitKey
End