GetLocalIP() with #NETWORKSERVER

Report any Hollywood bugs here
Post Reply
PEB
Posts: 537
Joined: Sun Feb 21, 2010 1:28 am

GetLocalIP() with #NETWORKSERVER

Post by PEB »

Try this code:

Code: Select all

CreateServer(1)
DebugPrint(GetLocalIP(1, #NETWORKSERVER))

OpenConnection(1, "www.google.com", 80)
DebugPrint(GetLocalIP(1, #NETWORKCONNECTION))
Using #NETWORKSERVER always returns "0.0.0.0" whatever machine runs it; but #NETWORKCONNECTION returns the actual local IP address for the machine.

User avatar
airsoftsoftwair
Posts: 4394
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: GetLocalIP() with #NETWORKSERVER

Post by airsoftsoftwair »

Ok, this looks like a bug. Will be fixed.

User avatar
airsoftsoftwair
Posts: 4394
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: GetLocalIP() with #NETWORKSERVER

Post by airsoftsoftwair »

Alright, so this isn't a bug. If you specify * as the ip$ (which is the default), CreateServer() will bind the server to all interfaces, i.e. typically the network interface (192.168.x.x) but also the loopback interface (127.0.0.1). Because of this, it's impossible for GetLocalIP() to return a single IP address because the server is bound to at least two interfaces. Thus, you just get the wildcard 0.0.0.0 as the return value. If you don't want that, bind the server to a single IP address by passing it in the ip$ argument to CreateServer().

PEB
Posts: 537
Joined: Sun Feb 21, 2010 1:28 am

Re: GetLocalIP() with #NETWORKSERVER

Post by PEB »

Interesting. So is there a way to get Hollywood to return the LocalIP address (assuming it's not known) without first making contact with the outside world (like using OpenConnection(1, "www.google.com", 80) does)?

User avatar
airsoftsoftwair
Posts: 4394
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: GetLocalIP() with #NETWORKSERVER

Post by airsoftsoftwair »

PEB wrote:
Mon Sep 07, 2020 9:17 pm
Interesting. So is there a way to get Hollywood to return the LocalIP address (assuming it's not known) without first making contact with the outside world (like using OpenConnection(1, "www.google.com", 80) does)?
It's possible but can be a little inconvenient. See here for an approach: viewtopic.php?f=4&t=2421&p=13090#p13085

A better way to do this is in the works, though.

PEB
Posts: 537
Joined: Sun Feb 21, 2010 1:28 am

Re: GetLocalIP() with #NETWORKSERVER

Post by PEB »

Sounds good.
Thanks for all the improvements you keep making.
(I'm eager to show my support by purchasing the newest version when it's ready for release.)

User avatar
airsoftsoftwair
Posts: 4394
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: GetLocalIP() with #NETWORKSERVER

Post by airsoftsoftwair »

Done now:

Code: Select all

- New: Added GetLocalInterfaces() to the network library; this will return a list of all interfaces that
  are currently available; it will return a table that contains "Name", "Address", and "Protocol" for each
  item; this allows you to conveniently determine a system's local IP address

Post Reply