MonoTouch,测试是否在本地网络上找到远程设备 [英] MonoTouch, test if remote device is found on local network

查看:63
本文介绍了MonoTouch,测试是否在本地网络上找到远程设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MonoTouch 开发一个应用程序,该应用程序将连接到网络上的远程设备.这些设备具有可以通过 http 查询访问的数据.

I am using MonoTouch to develop an app which will connect to remote devices on a network. These devices have data which can be access through http queries.

如果我为控制器提供了一个有效的 IP 地址,该应用程序可以完美运行,但是如果控制器不在网络上,它会挂起很长时间.出于这个原因,我认为最好使用 Reachability.cs 类,它可以在这里找到:

If I provide a valid IP address to a controller the app works perfectly, however it hangs for a long time if the controller is not on the network. For this reason I thought it would be good to use the Reachability.cs class which can be found here:

https://github.com/xamarin/monotouch-样本/blob/master/ReachabilitySample/reachability.cs

我没有使用 google.com 作为主机,而是使用控制器的 IP 地址.我读过这个类有一个错误,导致它不喜欢在 URL 的开头有http".现在已经尝试了很多事情来让这个工作,我没有想法.

Instead of using google.com as the host, I am using the IP address of the controller. I have read that there is a bug with this class which causes it to not like having "http" at the beginning of the URL. Having now tried numerous things to get this working I am out of ideas.

大家有什么建议吗?也许我在这里重新发明轮子.

Do anyone have any suggestions? Perhaps I am reinventing the wheel here.

推荐答案

现在已经尝试了很多方法来实现这一点,我已经没有想法了.

Having now tried numerous things to get this working I am out of ideas.

根据您的问题,不清楚您在 Reachability 类中遇到了什么问题.也许你可以编辑它并添加更多细节?例如到目前为止你尝试过的,它的反应如何:从不工作,抛出/崩溃,不一致的结果......

From your question it's not clear what issue you're having with the Reachability class. Maybe you could edit it and add more details ? e.g. what you tried so far, how it reacts like: never works, throws/crash, inconsistent results ...

大家有什么建议吗?

如果您的主要问题是阻塞应用程序的 UI,那么您可以(并且应该)异步(或单独的线程)进行连接和数据传输,并在完成后更新您的 UI(从主线程).

If your main issue is blocking the UI of your application then you could (and should anyway) do your connection and data transfer asynchronously (or a separate thread) and once completed update your UI (from the main thread).

例如使用 WebClient.DownloadDataAsync

这篇关于MonoTouch,测试是否在本地网络上找到远程设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆