Open GoogleCodeExporter opened 8 years ago
The library uses this to determine the local IPv4 address. I have not used Mono
so I don't know any workaround, if you find one please post it here.
Original comment by lidg...@gmail.com
on 19 Dec 2014 at 3:48
I found some solutions on StackOverflow
http://stackoverflow.com/questions/6803073/get-local-ip-address-c-sharp
the last solution works fine (tested on .NET 3.5 on Windows 8 and Mono 2.10 on
Mac & Linux), even with multiple network adapters enabled:
// class NetUtility.cs
/// <summary>
/// Gets my local IPv4 address (not necessarily external) and subnet mask
/// </summary>
public static IPAddress GetMyAddress(out IPAddress mask)
{
mask = null;
#if __ANDROID__
try
{
Android.Net.Wifi.WifiManager wifi = (Android.Net.Wifi.WifiManager)Android.App.Application.Context.GetSystemService(Android.App.Activity.WifiService);
if (!wifi.IsWifiEnabled) return null;
var dhcp = wifi.DhcpInfo;
int addr = dhcp.IpAddress;
byte[] quads = new byte[4];
for (int k = 0; k < 4; k++)
{
quads[k] = (byte) ((addr >> k * 8) & 0xFF);
}
return new IPAddress(quads);
}
catch // Catch Access Denied errors
{
return null;
}
#endif
// acquire local IP address by creating connection and taking it's address
// (which is preferred outbound IP address)
// http://stackoverflow.com/questions/6803073/get-local-ip-address-c-sharp
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
{
socket.Connect("10.0.2.4", 65530);
IPEndPoint endPoint = (IPEndPoint)socket.LocalEndPoint;
return endPoint.Address;
}
}
Original comment by vladimir...@gmail.com
on 22 Dec 2014 at 3:50
The portforwarding on Mono is still not working.
The solution posted above by me is works fine.
Original comment by vladimir...@gmail.com
on 3 Apr 2015 at 4:50
Which Platform*.cs file gets used in your solution? Are there any global
defines I can use to determine correct platform file? Are you using unity (so
UNITY_STANDALONE_OSX is defined?)
Original comment by lidg...@gmail.com
on 3 Apr 2015 at 9:15
I'm sorry, I did mention not the latest version of source, where you not yet
implemented multi-platform feature.
The platform is Mono, we're using UPNP port forwarding on Mac and Linux
platforms. We using it not only in Unity but in a standalone Mono application
also.
Regards!
Original comment by vladimir...@gmail.com
on 3 Apr 2015 at 9:22
Original issue reported on code.google.com by
vladimir...@gmail.com
on 19 Dec 2014 at 3:33