我最近访问了 heroku.com 网站并尝试在那里部署我的第一个 java 程序,实际上我使用他们的 java 部署教程有一个良好的开端,并且运行正常。现在我有一个需要在那里部署的服务器代码,我尝试按照示例进行操作,但我有一些问题,例如,
1-在这种情况下主机是什么,我已经尝试过应用程序链接,就好像它是主机一样,但它会抛出错误,
这是我的示例服务器代码
public class DateServer {
/** Runs the server. */
public static void main(String[] args) throws IOException {
ServerSocket listener = new ServerSocket(6780);
try {
while (true) {
Socket socket = listener.accept();
try {
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println(new Date().toString());
} finally {
socket.close();
}
}
} finally {
listener.close();
}
}
}
这是我的客户代码
public class DateClient {
/** Runs the client as an application. First it displays a dialog box asking for the IP address or hostname of a host running the date server, then connects to it and displays the date that it serves. */
public static void main(String[] args) throws IOException {
//I used my serverAddress is my external ip address
Socket s = new Socket(serverAddress, 6780);
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
String answer = input.readLine();
JOptionPane.showMessageDialog(null, answer);
System.exit(0);
}
}
我在他们的网站上按照本教程https://devcenter.heroku.com/articles/java上传了我的服务器代码,我还需要做些什么吗?!
提前致谢