if(Application.internetReachability != NetworkReachability.NotReachable)
{
isConnected = true;
Debug.Log("Success Connect");
}
else
{
isConnected = false;
Debug.Log("Failed Connect");
}
After updating Unity to the latest version, Application.internetReachability always returns NotReachable on Android phones.
There were no problems when using 2019.1.x, but problems arose from 2019.2.1 to the latest version.
Is there anything I need to do in the new version?
Please reply. Thank you.
Related
How to fix it?
In general, my task is to write a function that connects to a Wifi point. It returns True if the password is correct and False otherwise. I had Api version 31 by default, but my code did not work and I decided to put 28, since I have Android 9 on my phone.
private async Task<bool> ConnectWifi(string ssid, string pass)
{
try
{
wifi.SetWifiEnabled(true);
var formssid = $"\"{ssid} \"";
var formpass = $"\"{pass} \"";
var config = new WifiConfiguration
{
Ssid = formssid,
PreSharedKey = formpass,
Priority = 0
};
var result = wifi.AddNetworkPrivileged(config);
if (result.NetworkId == -1)
return false;
wifi.EnableNetwork(result.NetworkId, true);
return true;
}
catch { }
return false;
}
The best practice is to target the latest android version and set the minimum target version to Android 9 or below, so you can use it on your phone. Anything else doesn't really make sense :/
I still getting the same error on every device I have while using SQLite:
"System.DllNotFoundException: /system/lib/libsqlite.so occurred"
It always happens on this line:
var r = SQLite3.Open (databasePathAsBytes, out handle, (int) openFlags, IntPtr.Zero);
What can I do?
EDIT: Is this function correct used???:
public bool CreateDatabase()
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "CryptoSimulator.db")))
{
connection.CreateTable<Portfolio>();
connection.CreateTable<Wallet>();
connection.CreateTable<Assignments>();
return true;
}
}
catch(SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
i did have a same problem try to downgrade your Xamarin if you are on Windows but mac seems to be stable
I am trying to get old games out of Masterserver.PollHostData(). When a game is finished an I run the following script the client still gets the game from PollHostData().
if(Network.isClient)
{
if (Network.connections.Length == 1)
{
Debug.Log("Disconnecting from server");
Network.CloseConnection(Network.connections[0], true);
MasterServer.UnregisterHost(); //Tried UnregisterHost() first as well.
}
else
{
Debug.Log("Not connected to server");
}
}
else if (Network.isServer)
{
if (Network.connections.Length > 0)
{
Network.Disconnect(1000);
MasterServer.UnregisterHost(); //Tried UnregisterHost() first as well.
}
else
{
Debug.Log("No clients connected.");
Network.Disconnect(0);
MasterServer.UnregisterHost(); //Tried UnregisterHost() first as
}
}
However if the client restarts the game I won't get the HostData of the previous game anymore. I have tried clearing hostData before polling for it again but without success. The player who created the server does not get the game, which is strange since I clear my hostData array before assigning it again.
I found some old posts saying UnregisterHost is not working, if so what are my options?
First of all, i don't understand why
MasterServer.UnregisterHost(); //Tried UnregisterHost() first as well.
is here. Because master server has server information,not client information.
if(Network.isClient)
{
if (Network.connections.Length == 1)
{
Debug.Log("Disconnecting from server");
Network.CloseConnection(Network.connections[0], true);
MasterServer.UnregisterHost(); //Why?
}
else
{
Debug.Log("Not connected to server");
}
}
Solution is:
On Client side, you need to call MasterServer.ClearHostList(); before request list from MasterServer.
I wanted to check whether my phone can connect to Internet or not. I have seen several questions already. One of those is Question . It says to use NetworkInterface.GetIsNetworkAvailable() this and i tried it. I have disconnected my PC from internet and Also turned off the DataConnection of the emulator but NetworkInterface.GetIsNetworkAvailable() this always returning true. But simultaneouly i also check for NetworkInterfaceType.None and interestingly it is coming null.
Can anybody explain where i am missing info ?
Attempt : -
public static void CheckNetworkAvailability()
{
// this is coming true even when i disconnected my pc from internet.
// i also make the dataconnection off of the emulator
var fg = NetworkInterface.GetIsNetworkAvailable();
var ni = NetworkInterface.NetworkInterfaceType;
// this part is coming none
if (ni == NetworkInterfaceType.None)
IsConnected = false;
}
any help is appreciated :)
I am using following code to check if the device has access to internet with if it is connected to wifi or data connection..
public void UpdateNetworkInformation()
{
// Get current Internet Connection Profile.
ConnectionProfile internetConnectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
//air plan mode is on...
if (internetConnectionProfile == null)
{
Is_Connected = false;
return;
}
//if true, internet is accessible.
this.Is_InternetAvailable = internetConnectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
// Check the connection details.
else if (internetConnectionProfile.NetworkAdapter.IanaInterfaceType != 71)// Connection is not a Wi-Fi connection.
{
Is_Roaming = internetConnectionProfile.GetConnectionCost().Roaming;
/// user is Low on Data package only send low data.
Is_LowOnData = internetConnectionProfile.GetConnectionCost().ApproachingDataLimit;
//User is over limit do not send data
Is_OverDataLimit = internetConnectionProfile.GetConnectionCost().OverDataLimit;
}
else //Connection is a Wi-Fi connection. Data restrictions are not necessary.
{
Is_Wifi_Connected = true;
}
}
Edit:
And for simple internet connection you can use below code.
System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
Hope this helps!
The emulator always returns NetworkInterface.GetIsNetworkAvailable() as true, even if you emulate network conditions as having no network.
I faced this problem myself and the only truly way of testing this behaviour is to deploy the application to a physical device running Windows Phone and test it with the data turned off.
NetworkInterface.GetIsNetworkAvailable() checks the network connection and not the internet connection. If you are in any kind of network, then it will return true whether internet is present or not.
You can check the internet connection as following:
using System.Net
private bool IsOnline()
{
try
{
IPHostEntry iPHostEntry = Dns.GetHostEntry("www.wikipedia.com");
return true;
}
catch (SocketException ex)
{
return false;
}
}
using IPC over local TCP to communicate from Client to a Server thread. The connection itself doesn't seem to be throwing any errors, but every time I try to make one of the associated calls, I get this message:
System.Runtime.Remoting.RemotingException: Could not connect to an IPC Port: The System cannot Find the file specified
What I am attempting to figure out is WHY. Because this WAS working correctly, until I transitioned the projects in question (yes, both) from .NET 3.5 to .NET 4.0.
Listen Code
private void ThreadListen()
{
_listenerThread = new Thread(Listen) {Name = "Listener Thread", Priority = ThreadPriority.AboveNormal};
_listenerThread.Start();
}
private void Listen()
{
_listener = new Listener(this);
LifetimeServices.LeaseTime = TimeSpan.FromDays(365);
IDictionary props = new Hashtable();
props["port"] = 63726;
props["name"] = "AGENT";
TcpChannel channel = new TcpChannel(props, null, null);
ChannelServices.RegisterChannel(channel, false);
RemotingServices.Marshal(_listener, "Agent");
Logger.WriteLog(new LogMessage(MethodBase.GetCurrentMethod().Name, "Now Listening for commands..."));
LogEvent("Now Listening for commands...");
}
Selected Client Code
private void InitializeAgent()
{
try
{
_agentController =
(IAgent)RemotingServices.Connect(typeof(IAgent), IPC_URL);
//Note: IPC_URL was originally "ipc://AGENT/AGENT"
// It has been changed to read "tcp://localhost:63726/Agent"
SetAgentPid();
}
catch (Exception ex)
{
HandleError("Unable to initialize the connected agent.", 3850244, ex);
}
}
//This is the method that throws the error
public override void LoadTimer()
{
// first check to see if we have already set the agent process id and set it if not
if (_agentPid < 0)
{
SetAgentPid();
}
try
{
TryStart();
var tries = 0;
while (tries < RUNCHECK_TRYCOUNT)
{
try
{
_agentController.ReloadSettings();//<---Error occurs here
return;
} catch (RemotingException)
{
Thread.Sleep(2000);
tries++;
if (tries == RUNCHECK_TRYCOUNT)
throw;
}
}
}
catch (Exception ex)
{
HandleError("Unable to reload the timer for the connected agent.", 3850243, ex);
}
}
If you need to see something I haven't shown, please ask, I'm pretty much flying blind here.
Edit: I think the issue is the IPC_URL String. It is currently set to "ipc://AGENT/AGENT". The thing is, I have no idea where that came from, why it worked before, or what might be stopping it from working now.
Update
I was able to get the IPC Calls working correctly by changing the IPC_URL String, but I still lack understanding of why what I did worked. Or rather, why the original code stopped working and I needed to change it in the first place.
The string I am using now is "tcp://localhost:63726/Agent"
Can anyone tell me, not why the new string works, I know that...but Why did the original string work before and why did updating the project target to .NET 4.0 break it?