[英]Why does IAsyncResult.AsyncWaitHandle.WaitOne return false when wifi has no internet connection and mobile data is turned on? (XAMARIN)
I'm trying to do a sync with my custom device via wifi connection.我正在尝试通过 wifi 连接与我的自定义设备同步。 Everything works fine when my mobile data is turned off, but when it's turned on it won't work (because my custom device has no connection to the inte.net).
当我的移动数据关闭时,一切正常,但当它打开时,它将无法工作(因为我的自定义设备没有连接到 inte.net)。
This is where the problem happens:这是问题发生的地方:
stateSuccess = true;
tcpclnt = new TcpClient();
IAsyncResult ar = tcpclnt.BeginConnect(ip, port, new AsyncCallback(connectCallback), stateSuccess);
int timeout = 3000;
stateSuccess = ar.AsyncWaitHandle.WaitOne(timeout, false);
when I have mobile data turned on stateSuccess = false
, but when mobile data is turned off stateSuccess = true
.当我打开移动数据时
stateSuccess = false
,但是当移动数据关闭时stateSuccess = true
。 I'm always connected over wifi to my custom device.我总是通过 wifi 连接到我的自定义设备。
My connectCallback is:我的 connectCallback 是:
private void connectCallback(IAsyncResult ar)
{
var stateSuccess = (Boolean)ar.AsyncState;
try
{
tcpclnt.EndConnect(ar);
}
catch (Exception exc)
{
//handle
}
try
{
if (tcpclnt != null && tcpclnt.Connected && stateSuccess)
return;
tcpclnt.Close();
}
catch (Exception exc)
{
if (tcpclnt != null)
tcpclnt.Close();
}
}
I think the problem is somewhere in it chosing the wrong.network.我认为问题出在某个地方选择了错误的网络。 How can I force it to use wifi.network even thou the wifi has no inte.net connection?
即使 wifi 没有 inte.net 连接,我如何强制它使用 wifi.network?
The devices do not care nor discriminate the lower-level base-band radio scanning (we're talking about telephony here), that is left to the actual radio firmware to deal with.这些设备不关心也不区分较低级别的基带无线电扫描(我们在这里谈论的是电话),这是留给实际的无线电固件来处理的。
If you dont want to use WIFI, turn it off.如果您不想使用 WIFI,请将其关闭。 But if you want to force use WIFI, just turn your cellular data off
但是如果你想强制使用 WIFI,只需关闭你的蜂窝数据
Edit: I just found a workaround to this that works ONLY for Android: https://stackoverflow.com/a/56590566/11104068编辑:我刚刚找到了一个仅适用于 Android 的解决方法: https://stackoverflow.com/a/56590566/11104068
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.