2016-05-01 254 views
2

我在谷歌上運行的套接字服務器計算引擎使用靜態IP,繼承人如何我啓動服務器:谷歌計算引擎+插座

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; 
} 

因此,使用我的Android應用程序我嘗試連接到服務器,它運行我的家用電腦就OK了,但是當我嘗試連接到我的谷歌Compute Engine的VM超時:

java.net.ConnectException: failed to connect to /146.148.66.128 (port 4800): connect failed: ETIMEDOUT (Connection timed out) 

回答

1

對不起,如果這是顯而易見的,但是你open the firewall on the GCE VM

默認情況下,GCE虛擬機擁有除互聯網阻止的SSH以外的所有流量。

+0

是的,這是問題,我只在機器內部做防火牆配置。 –

+0

如果它適合您,請隨時接受答案。 :-) –