📄 threadedscoreserver.java
字号:
// ThreadedScoreServer.java
// Andrew Davison, March 2002, dandrew@ratree.psu.ac.th
/* A threaded server that stores a client's score (and name) in a
list of top-10 high scores.
The list is maintained in a file SCORFN, and loaded when the
server starts.
The server is terminated with a ctrl-C
The server processes a client by creating a
ThreadedScoreHandler object.
Derived from ThreadedEchoServer.java (Listing 3-5, p.161) in
Core Java 2, Volume II -- Advanced Features
Horstmann and Cornell
Sun Microsystems Press, 2000, 4th Edition
*/
// import java.io.*;
import java.net.*;
public class ThreadedScoreServer
{
private static final int PORT = 1234;
private HighScores hs;
public ThreadedScoreServer()
// Concurrently process clients forever
{
hs = new HighScores();
try {
ServerSocket serverSock = new ServerSocket(PORT);
Socket clientSock;
String cliAddr;
while (true) {
System.out.println("Waiting for a client...");
clientSock = serverSock.accept();
cliAddr = clientSock.getInetAddress().getHostAddress();
new ThreadedScoreHandler(clientSock, cliAddr, hs).start();
}
}
catch(Exception e)
{ System.out.println(e); }
} // end of ThreadedScoreServer()
// -----------------------------------
public static void main(String args[])
{ new ThreadedScoreServer(); }
} // end of ThreadedScoreServer class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -