如何在 Android 应用程序中使用 3G 互联网连接?

发布于 2024-09-01 13:36:32 字数 94 浏览 10 评论 0原文

我制作了一个应用程序,可以连接到我在服务器上运行的程序,但它似乎只适用于 WiFi。当我尝试使用 3G 时,却无法建立连接。为了使用 3G,我必须打开或设置一些特殊的东西吗?

I have made an App that can connect to a program that I am running on a server, but it only seems to work with WiFi. When I try to use 3G it doesn't make the connection. Is there something special that I have to turn on or set in order to use 3G?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

花之痕靓丽 2024-09-08 13:36:32

在应用程序级别,您(通常)不必担心手机可以使用哪些数据连接。

您是否研究过诸如当您使用 WiFi 时您可以访问网络服务器之类的问题,因为您是从网络内访问它的。然而,它可能根本无法从公共互联网访问,这就是 3G 连接尝试连接到服务器的方式。

您在 3G 上遇到什么错误/异常?

At the application level you (normally) don't have to worry about what data connection is available to the phone.

Have you looked into problems such as when you use WiFi you web server is accessible since you are hitting it from within your network. Whereas, it may not be accessible at all from the public internet which is how the 3G connection will be trying to connect to the server.

What error / exception do you get on 3G?

不即不离 2024-09-08 13:36:32

问题是我正在使用的端口。我使用的是 4444,但事实证明许多网络都阻止该端口。端口 1024 似乎适用于大多数情况。

The problem was the port I was using. I was using 4444, but it turns out that many networks block that port. Port 1024 seems to work for most.

吾性傲以野 2024-09-08 13:36:32

无论如何,我也遇到了同样的问题。我的应用程序可以通过 WiFi 完美运行,但不能通过 3G。我在威瑞森。我还使用端口 4444,因为我认为这是我选择的“随机”端口。由于 Verizon Wireless 阻止了此端口,我花了一个多小时尝试诊断我的错误。我切换到444端口,现在工作正常。非常令人沮丧。希望这对其他人有帮助。

For what it's worth I was having the same exact problem. My app would work perfect over WiFi but not over 3G. I am on Verizon. I was also using port 4444 because I thought it was a "random" port I had chosen. Thanks to Verizon Wireless blocking this port I spent over an hour trying to diagnose my error. I switched to port 444 and it works fine now. Very frustrating. Hopefully this will help someone else.

傲娇萝莉攻 2024-09-08 13:36:32

Wifi 和 3G 之间不应该有任何额外的东西。我在清单权限中包含的所有内容都是 android.permission.INTERNET,并且可以在 Wifi 或 3G 上正常工作,因此假设 Wifi 也需要 INTERNET(我对此并不完全确定,因为我还没有尝试了 JUST Wifi)并且您已经将其包含在内,我不知道还有什么。

如果碰巧 Wifi 不需要互联网,并且碰巧没有互联网也能工作,则清单中应包含这样一行:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

应该为您的手机授予互联网(和 3G)访问权限。抱歉,如果这不能回答问题,但我想不出当 Wifi 工作正常时 3G 会成为问题的任何其他原因。此外,确保您可以从另一个外部位置访问网络 - 正如我之前所说,这可能是安全问题,以某种方式阻止外部访问。 (不确定您使用3G连接什么)

There shouldn't be anything additional between Wifi, and 3G. All I've included in my Manifest Permissions is android.permission.INTERNET, and that works fine with either Wifi or 3G, so assuming INTERNET is required for Wifi as well (which I'm not entirely sure about, since I haven't tried JUST Wifi) and you've already included it, I don't know of anything else.

If by some chance Wifi does NOT require INTERNET, and it happens to work without it, the Manifest should include a line like:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

which should grant internet (and 3G) access for your phone. Sorry if that doesn't answer the question, but I can't think of any other reason 3G would be an issue when Wifi works fine. Additionally, make sure you can access the network from another outside location--as said before me, it may be a matter of security preventing outside access somehow. (Not sure what you're using 3G to connect to)

记忆里有你的影子 2024-09-08 13:36:32

创建套接字时抛出的异常是 IOException,并且达到超时 (4000)。当手机处于 Wi-Fi 状态时,它工作正常,但当它使用 3G 时,插座无法连接到主机/端口。

The exception that is getting thrown when the socket is made is an IOException, and the timeout (4000) gets reached. When the phone is in Wi-Fi it works fine but when it uses 3G the socket cannot connect to the host/port.

时光沙漏 2024-09-08 13:36:32

您必须咨询您的电话公司(祝您好运,找到可以接听的人!!)3G 网络不会阻止您希望打开的端口(并且处于 WiFi 模式时)。一些电信公司几乎阻止了您期望的所有 3G 网络标准(并且您的应用程序堆栈假设可用)(ping、telnet、RDP 等)。

You'll have to check with your phone company (and good luck in finding someone who can answer!!) that the 3G network doesn't block ports that you're expecting to be open (and are when in WiFi mode). Some telcos block almost everything you'd expect (and your app stack assumes to be available) to be standard on 3G nets (ping, telnet, RDP etc., etc.).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文