套接字连接到 8443 可以,但不能连接到 443?

发布于 2024-12-07 13:55:38 字数 976 浏览 0 评论 0原文

我正在android上做一些套接字编程(注意我说的是套接字,而不是HttpClient或HttpUrlConnection),我遇到了一个非常奇怪的问题,我无法在端口443上连接到我的tomcat服务器,但8443没问题。我的代码非常简单,这就是全部:

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    try{
        Socket s = new Socket();
        InetSocketAddress addr = new InetSocketAddress("10.1.1.1", 443);
        s.setKeepAlive(true);
        s.setSoTimeout(300000);
        s.connect(addr);
    }catch{<my catch statement>}
}

仅此而已。我将程序推送到我的设备并启动它,但它总是抛出 SocketException:操作超时 错误。但是,如果我将服务器端和代码端的端口都切换为 8443,我的设备可以正常连接。我所做的只是更改 server.xml 文件中的数字。

还有一些有趣的事情需要注意,如果我在计算机上的模拟器中运行完全相同的东西,它就可以正常工作。我还在设备和计算机之间的连接上运行了wireshark,看起来它不断返回ICMP Destination Unreachable: Destination Port Unreachable。当我可以从我的设备上 ping 通它时,怎么可能呢?

我想看看这是否更适合服务器故障,但从那里的常见问题解答来看,它似乎更适合专业而不是个人服务器问题。有谁知道为什么 Android 设备无法连接到我的服务器上的某些端口,而我的模拟器可以?为什么切换到8443突然就可以连接了?

I'm doing a little bit of socket programming on android (note I said socket, not HttpClient or HttpUrlConnection) and I'm running into a very strange issue where I cannot make a connection to my tomcat server on port 443 but 8443 is fine. My code is very simple, this is all there is to it:

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    try{
        Socket s = new Socket();
        InetSocketAddress addr = new InetSocketAddress("10.1.1.1", 443);
        s.setKeepAlive(true);
        s.setSoTimeout(300000);
        s.connect(addr);
    }catch{<my catch statement>}
}

That's all. I push the program to my device and launch it but it always throws a SocketException: Operation Timed Out error. However, if I switch the port on both the serverside and code side to 8443, my device can connect no problem. I am doing nothing more than changing the number in the server.xml file.

Couple of things that are interesting to note as well, if I run the same exact thing in an emulator on my computer, it works just fine. I also ran wireshark on the connection between the device and my computer and it looks like it keeps throwing back an ICMP Destination Unreachable: Destination Port Unreachable. How can that be when I can ping it from my device?

I looked to see if this was more appropriate on serverfault but from the FAQ over there, it seems more geared towards professional rather than personal server issues. Does anyone have any idea why an android device can't connect to certain ports on my server when my emulator can? And why does the switch to 8443 suddenly allow the connection to work?

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

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

发布评论

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

评论(1

孤者何惧 2024-12-14 13:55:38

您的 Android 设备和服务器之间是否存在桌面(模拟器)和服务器之间不存在的防火墙?

Is there a firewall between your Android device and your server that isn't present between your desktop (the emulator) and your server?

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