I am trying to get my Android application to connect to a socket on a server over the Internet. I notice that when I have Wi-Fi turned on in the phone, the application can successfully connect to the port, but if I turn off Wi-Fi, I get a timeout in the connection. I can easily browse and browse the Internet on the phone when Wi-Fi is disconnected, but the connection to this server always fails.
I checked that the server is listening on this port, and I can always connect from any other computer via the Internet and on the phone if Wi-Fi is turned on.
I am wondering what might be different from using a wireless connection and connecting a cell to get to this place. The IP address that I use to connect to the address is publicly available.
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("XXXX", 4444); out = new PrintWriter(kkSocket.getOutputStream(), true); } catch (UnknownHostException e) { System.err.println("Don't know about host: XXXX"); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: XXXX"); }
Tag
source share