How Get Computer IP Address from Within GameInfo or PC class? GetNetDriver() returns NULL

Dear Friends at Epic,

I’ve seen the IPAddress.h and socket header files

I am wondering, what is the fastest way I can retrieve the computer’s IP address from within the GameInfo or PlayerController class ?

Thanks!

:slight_smile:

Rama

wooohooo code has good coloring now! Thanks Epic!

//IPAddress.h
/**
	 * Sets the ip address from a host byte order uint32
	 *
	 * @param InAddr the new address to use (must convert to network byte order)
	 */
	virtual void SetIp(uint32 InAddr) = 0;
	
	/**
	 * Sets the ip address from a string ("A.B.C.D")
	 *
	 * @param InAddr the string containing the new ip address to use
	 */
	virtual void SetIp(const TCHAR* InAddr, bool& bIsValid) = 0;

By the way I have never succeeded in getting a pointer to the OnlineSubsystem, so I hope that is not the recommended solution to my IP question :slight_smile:

I’ve been having ongoing discussion with Dmitry and Josh about it and we concluded to wait till Beta5

Some other way to get IP please?

(here’s my code as a reference to what I mean about OnlineSubsystem being Null)

		IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
	if (OnlineSub)
	{
		IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
		if (Sessions.IsValid())
		{
			Optimize("onlinesubsys was found!!!! yay!!");
			
		}
		else Optimize(" IOnlineSessionPtr not found, did you change config to enable steam?");
	}
	else Optimize("onlinesubsys not found, did you change config to enable steam?");

Let’s take a step back here and try to understand the pieces involved. The GameInfo (recently renamed GameMode), does not have any information about the network. The network information is contained completely within the NetDriver class. The world (GetWorld()) has a net driver on it ONLY if you are actively hosting a game at present (via ?listen on the commandline or ServerTravel() function call), a client connected to a server, or dedicated server which always launches with a listening net driver.

You can see what net drivers are around via the GEngine variable and its FindNamedNetDriver() function. Passing in GameNetDriver would give you the main net driver responsible for hosting a game with clients.

Clients have a PendingNetDriver while they are trying to connect to hosts, this driver moves over to the world and becomes the GameNetDriver when they connect.

Now that this has been said, just getting the IP may be a lost cause depending on what you are trying to do. Most people these days are behind routers and the IP address you will get there is always the local ip (192.x.x.x or 10.x.x.x). You need a relay service to tell you what your external address is. Steam does this for you for free via Steam sockets, but the “ip address” they use doesn’t look like what you’d expect. In UE4 it is expressed as “steam.myid” and I pass that value into the various Steam functions. The FSocket::GetIP() function doesn’t return anything for Steam because it doesn’t conform to typical (BSD) sockets. Under the hood Steam will auto connect the host and client, using its own relay service if the NAT restrictions can’t be overcome.

We don’t provide any way to convert internal IPs to external IPs since we don’t provide master server functionality like Valve does.

What are you trying to do? I can see how I might be able to help you more directly.

1 Like

"has a net driver on it ONLY if you are actively hosting a game at present "

Ahh I was missing this part

When I actually host I do get an IP, and it um… is:

0.0.0.0

But hey!

I do actually have an external server service that I am using thanks to William Gaul called Sagittarius, so I can use that.

I was hoping to be able to tell others who are not using Sagittarius how to get their IP

But since we’ve not figured steam out yet in my situation we can revisit this idea in Beta5 using:

steam.myid

Thanks for the info Josh!

Can’t wait to try out Steam in Beta5 !

:slight_smile:

Rama

Ah, sorry, the 0.0.0.0 is the INADDR_ANY address, which effectively means listen on any network interface on the PC. For a PC with 1 NIC then this is effectively “use that card’s IP address”. But as stated before, this is going to be your LAN (not WAN) address.

Thanks for the info Josh!

:slight_smile:

I am looking forward to steam.myid in beta5 :slight_smile:

:slight_smile:

I don’t know how to do it from the client’s computer, but since I know you’re using this for Sagittarius, just pass the string {{IP}} as the IP when you create a new server, and the App Engine app will automatically detect your computer’s IP for you.

And actually, I discovered while making Sag that it’s near-impossible for a computer to “know” its own IP without sending a round-trip ping to a remote server. For example, the IP you see in command line or terminal is often just the local network IP (behind a router) or worse a mask. This IP will not work when trying to connect to a multiplayer game.

that’s what I needed to know for working with your project, thanks William!

The question of how UE4 handles this is still very interesting to me though :slight_smile:

Haha yeah I’d like to know too if it’s even possible :stuck_out_tongue: Although, in reality it’s not really necessary since some game service like OnlineSubsystem or Steam should handle it.

yea I’d still really like to hear from an awesome Epic Dev (hint: you’re all awesome) about this

:slight_smile:

Rama

I think you can do something like GetWorld()->GetNetDriver()->LowLevelGetNetworkNumber() - that might give you what you are looking for but I am not 100% sure.

Great to hear from you Dave!

Actually, trying to do that has helped to flesh out why I cant get Steam to work

When I call

GetWorld()->GetNetDriver()->LowLevelGetNetworkNumber();

it crashes my game!

I apparently am not succesffuly having any netdriver()

buuut

I can host real multipalyer games using the shootergame code


how is that possible I wonder?

If I add this check

UNetDriver* TheNet = GetWorld()->GetNetDriver();
if(!TheNet)
{
	Optimize("Net Driver is NULL!!!");
	return;
}
else Optimize(TheNet->LowLevelGetNetworkNumber());

Then I get the message that the net driver is indeed NULL and no crash

Soooooo

How have I hosted real multiplayer games with Epic Folks and people far across the USA including Hawaii

without a net driver?

:slight_smile:

:slight_smile:

Rama

PS: It’s not GetWorld(), I spawn lots of stuff from this same class

PSS: here’s part of my defaultengine.ini,I am using beta4 :slight_smile:

[Core.Log]
LogOnline=verbose ;online logging
LogAnalytics=log

[/Script/Engine.GameEngine]
!NetDriverDefinitions=ClearArray
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystem.IpNetDriver")
+NetDriverDefinitions=(DefName="NoSteamNetDriver",DriverClassName="OnlineSubsystem.IpNetDriver",DriverClassNameFallback="OnlineSubsystem.IpNetDriver")

[OnlineSubsystem]
;DefaultPlatformService=Null
DefaultPlatformService=Steam
PollingIntervalInMs=20

Where did you get that defaultengine.ini? (Did you edit it yourself or are we providing that config in rocket beta 4?)

Under [Core.Log] - try setting “LogNet=Log” then run. See if you can find anything in the logs like “CreateNamedNetDriver failed to create driver”. That might give us some clues.

I got most fhte engini.ini code form the shootergame example

It’s pretty clear that the onlinesubsystem is not loading propery via this first part of my log :slight_smile:

Again, I am able to host multiplayer games, sooo im not sure what htis all means as to why GetNetDriver() is not working (but I cant host steam, only via Open IP)

Thanks Dave!

I’m really not sure what level of support Rocket beta has for steam integration. I realize the engine supports it as a whole, but I am not sure what is required for rocket beta projects to use it. Adding some people to the thread that might have insight.

Previously I have discussed this matter with Josh and Dmitry and they suggested we wait till Beta5 to try again

https://rocket.unrealengine.com/questions/6140/steam-c-how-do-i-access-the-instance-of-the-online.html

So hopefully GetNetDriver() will not return NULL at that point too!

Thanks again Dave!

(meantime I have still been able to test real multiplayer games using open IP so all’s well :slight_smile: )

:heart: