Java Reference
In-Depth Information
L ISTING 6.4 Continued
out.writeInt(size);
System.out.println( header + “Command: GET “+path+” size:”+size );
if (f.exists()) {
FileInputStream fis = new FileInputStream;
sendToClient(new DataInputStream(fis), path);
} else {
// resource not found,
// send back an empty msg
sendToClient(new DataInputStream(new ByteArrayInputStream(new
byte[0])), path+”(not found)”);
}
}
if (command==POST_COMMAND) {
//read the incoming array because it is the posted data
String data = in.readUTF();
System.out.println( header + “Command: POST (data=\””+data+”\”)”);
}
}//-while
System.out.println( header + “shutting down client connection”);
out.close();
in.close();
clientSocket.close();
// to avoid troubles in a multi-threaded environment
// saveProperties();
} catch (IOException e) {
System.out.println( header + “Main while: “+e);
System.exit(-1);
}
}
/**
* implements the check Command, server-side
*/
private void executeCheck() {
// change name
String tName = Thread.currentThread().getName();
Thread.currentThread().setName(“Deployment-”+tName);
header = “BankServer[“+Thread.currentThread().getName()+”] - “;
try {
String clientId = in.readUTF();
String[] clientRecord = read(clientId);
if (clientRecord==null) {
write(clientId, DEFAULT_POLICY, “1.0”, null, null);
clientRecord = read(clientId);
Search WWH ::




Custom Search