我对此AWS虚拟机有疑问。我已经从安全组的任何位置设置了所有TCP,UDP,流量和ICMP,我的本地计算机可以将虚拟机ping到公共IP地址。但不知何故,如果我尝试使用本地计算机上的客户端服务器连接,套接字类无法连接到虚拟机上的其他类? 这是本地计算机上的客户端代码:
Socket clientSocket = new Socket(VMAdress, 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine();
这是虚拟机上的服务器代码:
ServerSocket welcomeSocket = new ServerSocket(6789);
while(true)
{
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
System.out.println("Received: " + clientSentence);
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
提前感谢您的帮助。