如何在 J2ME/BlackBerry 中 ping 服务器?
如何使用 java 对 J2ME/BlackBerry 中的服务器执行 ping 操作?这看起来很基本,但我在 javadoc 中找不到它。谢谢。
How do I ping a server in J2ME / BlackBerry using java? This seems basic, but I can't find it in the javadocs. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ping 需要向主机发送 ICMP 数据包,不幸的是,J2ME 和 BlackBerry API 不提供对网络的低级控制。您最多可以做的是建立到端点的 HTTP 或套接字连接。
Ping requires sending a ICMP packet to the host and unfortunately, J2ME and BlackBerry APIs do not give that low-level control over networking. The most you can do is establish HTTP or socket connections to an endpoint.
如果您的目标是确定是否具有 Internet 连接,则该解决方案比发送 ping 等价的解决方案要复杂得多。 BlackBerry 不像普通 PC 那样是普通的 IP 连接主机,因此具有许多不同的底层传输,可用于通过互联网连接到某些内容。其中包括:
因此,可靠地打开连接的问题通常可能涉及实际尝试上述传输的某些子集,并且可能很复杂以确定上述内容的可用性和覆盖范围。
如果您使用的是 BB OS 5.0,那么通过新引入的 ConnectionFactory API。如果您使用的是较旧的 BB 操作系统版本,RIM 提供了 网络诊断工具可以帮助您。它并不完美,您肯定需要进行认真的设备测试来解决问题,但它是学习必要 API 的实质内容的一个很好的起点。
If your goal is to determine whether or not you have Internet connectivity, the solution is a lot more complicated than an equivalent of sending a ping. The BlackBerry is not a normal IP-connected host like your average PC, and thus has many different underlying transports that can be used for connecting to something over the internet. These include:
So often the problem of reliably opening a connection can involve actually attempting some subset of the above transports, and it can be complicated to determine the availability and coverage of the above.
If you are using BB OS 5.0, then the problem is made much simpler through the newly introduced ConnectionFactory API. If you are using older BB OS versions, RIM has the sample code for a Network Diagnostic Tool available to help you out. Its not perfect, and you definitely need to do serious on-device testing to work out the kinks, but its a good starting point for learning the nitty-gritty of the necessary APIs.