开发者

Socket Connect to 8443 ok but not 443?

开发者 https://www.devze.com 2023-04-09 17:30 出处:网络
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 tom

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 ad开发者_运维知识库dr = 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号