我最近访问了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);
}
}
我按照Heroku网站上的教程https://devcenter.heroku.com/articles/java上传了我的服务器代码,还需要做其他事情吗?谢谢。