I'm running a socket server on a Google compute engine with static IP, heres how I start the server:
public class Server {
private static int port=4800;
public static void main(String argv[]) throws Exception {
System.out.println("STARTED ON PORT 4800!");
@SuppressWarnings("resource")
ServerSocket socketIn = new ServerSocket(port);
while (true) {
Socket socketConenection = socketIn.accept();
Thread t = new Thread(new ServerThread(socketConnection, connection));
t.start();
}
}
}
public static BufferedReader conectServer(String body, String function) throws IOException {
Socket socketClient = new Socket(ipServer, portServer);
DataOutputStream outToServer = new DataOutputStream(socketClient.getOutputStream());
BufferedReader fromServer = new BufferedReader(new InputStreamReader(socketClient.getInputStream()));
outToServer.writeBytes(function+ '\n' + body + '\n');
return fromServer;
}
So using my android app I try to connect to the server, it runs ok on my home PC, but when I try to connect to my Google Compute Engine VM it times out:
java.net.ConnectException: failed to connect to /146.148.66.128 (port 4800): connect failed: ETIMEDOUT (Connection timed out)