Problem connecting Android app to socket using cell connection

大憨熊 提交于 2019-12-22 08:04:08

问题


I'm trying to get my android app to connect to a socket on a server across the internet. I notice that when I have my Wi-fi turned on in the phone, the App can successfully connect to the port, but if I turn off the wi-fi, I get a time out on the connection. I can access and browse the internet on the phone seamlessly when wi-fi is off but connecting to that server always fails.

I've verified that the server is listening on that port and I can always connect from any other computer across the internet and on the phone if wi-fi is enabled.

I'm wondering what could be different between using the wireless connection and the cell connection to reach that location. The IP I'm using to connect to the address is a public address.

Button SendButton = (Button) findViewById(R.id.SendButton);


    SendButton.setOnClickListener(new Button.OnClickListener() {

        @Override
            public void onClick(View v) {
            Socket kkSocket = null;
            PrintWriter out = null;

    try {
        kkSocket = new Socket("X.X.X.X", 4444);
        out = new PrintWriter(kkSocket.getOutputStream(), true);
    } catch (UnknownHostException e) {
        System.err.println("Don't know about host: X.X.X.X");

    } catch (IOException e) {
        System.err.println("Couldn't get I/O for the connection to: X.X.X.X");

    }

来源:https://stackoverflow.com/questions/5749612/problem-connecting-android-app-to-socket-using-cell-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!