2
votes

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)
1

1 Answers

5
votes

Sorry if this is obvious, but did you open the firewall on the GCE VM?

By default, GCE VMs have all traffic except SSH blocked from the internet.