- Home /
Getting IP Address of clients (LL API)
I'm using Unity (C#) with LowLevel API for my networking. I saw some tutorials on how to set it up and send data between the server and the clients. (Everything works as intended).
Now I need a way to get an access to clients' IP Addresses from the server end. I tried using
NetworkTransport.GetConnectionInfo();
But the variable "out string address" seems to be removed. Intellisense from Visual Studio shows that there is "out string address" but when I start putting in variables, it isn't there. I'm using Unity 2018.11f1 if that helps.
I'm pretty sure there is a way, but if not, I'll just have a longer way of clients sending their IP address as data to the server when they log in.
Any help is appreciated.
Answer by Bunny83 · Oct 25, 2019 at 11:08 PM
I'm not sure what you mean by "it isn't there". You have to pass a variable as out parameter to that method in order to call it. And the method is required to assign any kind of value to that variable (it could be null or even an empty string). So what do you mean by "it isn't there"? Is the string empty?
Apart from that I don't see a reason why it shouldn't work. However may I ask what you need the client IP for? Since most clients nowadays are behind a NAT router the IP is in most cases pretty useless, no matter if it's the public (router) IP or the private client IP address. The point of the LL API was to abstract away the whole concept of the underlying protocols.
You are aware of the fact that Unity has deprecated the whole network API? It might still work but will probably be removed in the future.
I'm aware of how to use "out" variable. When I said "it isn't there" I meant the method is not taking that parameter unlike what it says on the document.
Take a look at the screenshots for better understanding. Intellisense shows that there is "address" section
However when I actually trying to call that method, that "address" parameter is gone.
This could be a bug I'm not aware of, or maybe it is deprecated.
I need to get an IP address from the user since that user will be running multiple exe applications separately (multiple Unity builds), so I need a way for the server to know they all belong to one user. Since IP address is unique to one device, I decided to use it.
Your images do not load, probably because of the non ASCII image names. Anyways I just had a look at the GetConnectionInfo method and it has two overloads. One that returns a string and another one that doesn't has a return type but returns the address as an out parameter. I just filled out all types and I don't get any error, just a warning that "NetworkTransport" is deprecated and that it will be removed in a future Untiy version:
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Types;
// [...]
string address;
int port;
NetworkID netID;
NodeID nodeID;
byte error;
NetworkTransport.GetConnectionInfo(0,0,out address, out port, out netID, out nodeID, out error);