Java Reference
In-Depth Information
L ISTING 6.4 Continued
6
private final static String NEWEST_POLICY = “newest”;
private final static String NO_DOWNLOADS_POLICY = “none”;
private final static String DEFAULT_POLICY = NEWEST_POLICY;
/**
* Constructor
*/
public BankServer(Socket s) {
clientSocket = s;
loadProperties();
}
/**
* The Thread's run
*/
public void run() {
header = “BankServer[“+Thread.currentThread().getName()+”] - “;
System.out.println( header + “Connection Accepted.”);
try {
out = new DataOutputStream(clientSocket.getOutputStream());
in = new DataInputStream(clientSocket.getInputStream());
} catch (IOException e) {
System.out.println( header + “creating streams “+e);
System.exit(-1);
}
char command = ' ';
try {
while ((command = in.readChar())!=-1) {
// process incoming command
if (command==QUIT_COMMAND) {
System.out.println( header + “Command: QUIT.”);
System.out.println( header + “Client closed session.”);
break;
}
if (command==CHECK_COMMAND) {
executeCheck();
}
if (command==GET_COMMAND) {
//read the incoming string because it is the path to the requested
file
String path = in.readUTF();
File f = new File(SERVER_DIR+path);
int size = (int)f.length();
Search WWH ::




Custom Search