我的连接很不稳定,但我有一个备份.我做了一些bash脚本来检查连接并改变连接,如果现有的已经死了.请帮我改进它们.
这些脚本几乎可以工作,除了没有等待足够长的时间来接收IP(它直到循环中的下一步循环太快).开始:
#!/bin/bash
# Invoke this script with paths to your connection specific scripts, for example
# ./gotnet.sh ./connection.sh ./connection2.sh
until [ -z "$1" ] # Try different connections until we are online...
do
if eval "ping -c 1 google.com"
then
echo "we are online!" && break
else
$1 # Runs (next) connection-script.
echo
fi
shift
done
echo # Extra line feed.
exit 0
Run Code Online (Sandbox Code Playgroud)
以下是slave脚本的示例:
#!/bin/bash
ifconfig wlan0 down
ifconfig wlan0 up
iwconfig wlan0 key 1234567890
iwconfig wlan0 essid example …
Run Code Online (Sandbox Code Playgroud) 我如何检查使用代码是否通过Wifi或GSM/3G在Android中进行连接?
如何使用广播接收器检查是否没有Internet连接?
在那之后:
1.如果有连接=什么也不做
2.没有连接=打开新活动
我希望你明白我在问什么.
这是我的webview应用代码:
WebView mWebView;
String URL = "http://url.com";
ProgressBar loadingProgressBar,loadingTitle;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.Web);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.loadUrl(URL);
mWebView.setWebViewClient(new MyWebViewClient());
loadingProgressBar=(ProgressBar)findViewById(R.id.progressBar);
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
loadingProgressBar.setProgress(newProgress);
if (newProgress == 100) {
loadingProgressBar.setVisibility(View.GONE);
} else{
loadingProgressBar.setVisibility(View.VISIBLE);
}
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode …
Run Code Online (Sandbox Code Playgroud) 我正在制作一个需要互联网连接的应用程序.我正在寻找检查互联网连接并返回警报视图的最佳方法.我已经找到了解决方法,只能找到在iOS 4中完成上述操作的方法,但我正在制作的应用程序是在iOS 5中.
我已经看过苹果Reachability示例代码了,但是当我尝试实现时,这只会让我的代码错误变得疯狂(因为它是为iOS 4构建的).
编辑:当我将reachability.h文件导入我的项目时,我得到10个错误(其中6个我可以简单地修复)和4个我不知道该怎么做.
iphone connectivity reachability ios5 automatic-ref-counting
我正在运行一个使用以下代码下载RSS提要的Windows服务:
XmlReaderSettings settings = new XmlReaderSettings() { DtdProcessing = DtdProcessing.Ignore };
string feedXml = XDocument.Load(XmlReader.Create(url, settings));
Run Code Online (Sandbox Code Playgroud)
该服务不在IIS下运行,而是作为独立服务运行.
突然之间(我怀疑是基础设施问题)我们开始每10-20分钟接收一次"无法连接到远程服务器".代码本身没有改变,我正在寻找可能的原因.
为了解决这个问题,我将服务移动到另一台机器,但问题仍然存在.
很想得到任何想法.谢谢!
我使用Microsoft.SmartDevice.Connectivity连接到Windows Phone 8.1操作系统,其中包含以下链接中的说明:使用控制台应用程序
连接到Windows Phone 8现在我可以连接到Windows Phone 8.1模拟器或Windows Phone 8.1设备,我可以启动任何应用程序使用他们的ProductID.
所以现在我想通过使用这个框架来安装我开发给这些设备的应用程序.我知道WP8.1的XAP包是一个.appx文件.要在此框架中安装1个应用程序,我使用InstallApplication()方法,如下所示:
IRemoteApplication remoteApplication = iDevice.InstallApplication(appID, appID, applicationGenre, iconPath, xapPackage);
Run Code Online (Sandbox Code Playgroud)
哪个appID是ProductID,我在Package.appxmanifest页面中得到它是:
556ee9d4-5640-4120-9916-44b1ca27352f
但我得到的例外是:
"An unhandled exception of type 'Microsoft.SmartDevice.Connectivity.SmartDeviceException' occurred in Microsoft.Smartdevice.Connectivity.dll
Additional information: An attempt was made to move the file pointer before the beginning of the file."
Run Code Online (Sandbox Code Playgroud)
当我使用Visual Studio提供的应用程序部署工具时,可以安装此应用程序,但是当我使用连接框架时,我无法安装它.
那么如何使用连接框架安装此应用程序?
请帮我.谢谢您的帮助.
我正在尝试检测是否确实存在互联网连接并且网站可以访问.我有一个广播接收器,在接收时运行以下方法:
public boolean hasInternetNow() {
Thread checkinternet = new Thread(new Runnable() {
@Override
public void run() {
try {
try {
ConnectivityManager cm = (ConnectivityManager) myContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo().isConnectedOrConnecting()) {
URL url = new URL("http://www.google.com");
HttpURLConnection urlc = (HttpURLConnection) url .openConnection();
urlc.setRequestProperty("User-Agent", "test");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(1000); // mTimeout is in seconds
urlc.connect();
if (urlc.getResponseCode() == 200) {
setinternetDetected(true);
} else {
setinternetDetected(false);
}
}
} catch (IOException e) {
e.printStackTrace();
setinternetDetected(false);
} catch (NullPointerException e){
e.printStackTrace();
setinternetDetected(false);
}
} catch (Exception …
Run Code Online (Sandbox Code Playgroud) 在下面的代码我试着得到IP
他的网络,但我得到的info.getIpAddress();
是
-25576378
Run Code Online (Sandbox Code Playgroud)
为什么?这是什么?
码
WifiInfo info = mWiFiMgr.getConnectionInfo();
String ssid;
int strength = WifiManager.calculateSignalLevel(info.getRssi(), 5);
String unit = WifiInfo.LINK_SPEED_UNITS;
int ip_add = info.getIpAddress();
int speed = info.getLinkSpeed();
Run Code Online (Sandbox Code Playgroud) 问:管理蓝牙连接的最佳做法是什么?
我已经阅读了android蓝牙指南和许多蓝牙连接教程.对封装设计和最佳实践没有帮助.
我以前从未编译过与外部设备的连接.我需要两个星期的时间来绕过扫描附近蓝牙设备的代码并将它们扔进ListView.听众,广播和适配器!
我的项目将在蓝牙收据打印机上每15分钟打印1-40张收据.目前,安全性不是问题.在同一个连接上,它也将接收数据(同时发送和接收似乎不是必要的,但会很有用).我还不确定如何在这个单个加密狗设备上配置设备,但我猜这些设备是通过USB控制器连接到加密狗的.
到目前为止,我有一个对象来管理单个I/O连接.静态地我打开一个活动来选择一个连接(以后在数据库中保存标签,mac和pin).根据教程,我有"打开","收听","发送"和"关闭"方法.令我困惑的是"如何"使用这些功能.我可以整天打开连接(10小时)并每隔3分钟使用一次吗?我应该在发送或请求数据时打开/关闭连接吗?我在哪里可以检测到需要重新连接?
我尝试使用此功能检查我的网络状态(已连接或已断开连接):
// Check Network status
private fun isNetworkAvailable(): Boolean {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE)
return if (connectivityManager is ConnectivityManager) {
val networkInfo = connectivityManager.activeNetworkInfo
networkInfo.isConnected
}
else false
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个 java.lang.IllegalStateException:networkInfo不能为null - 在断开网络运行时出错.为什么?我该如何解决这个问题?
connectivity ×10
android ×6
java ×2
.net ×1
android-wifi ×1
bash ×1
bluetooth ×1
c# ×1
ios5 ×1
iphone ×1
kotlin ×1
reachability ×1
unknown-host ×1