Problem connecting Android app to socket using cell connection
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 o开发者_C百科ut = 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");
}
精彩评论