小编Fel*_*nto的帖子

谷歌计算引擎 + 套接字

我正在使用静态 IP 在 Google 计算引擎上运行套接字服务器,这是我启动服务器的方式:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

}

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 …
Run Code Online (Sandbox Code Playgroud)

sockets android google-compute-engine google-cloud-platform

2
推荐指数
1
解决办法
1158
查看次数