Skip to content

Commit fc3ca12

Browse files
author
quaa
committed
Basic client layout, client to server talking added in pseudocode
1 parent ed2b422 commit fc3ca12

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

pseudocode.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,69 @@ if does not exist
2525
do nothing
2626
move to next file
2727
end
28+
29+
30+
31+
2 way talking:
32+
33+
CLIENT: dirName
34+
Server: EXISTS or NOEXISTS
35+
36+
if directory
37+
CLIENT: dirName DiR
38+
SERVER: OK
39+
else
40+
CLIENT: fileName lastModified
41+
SERVER: OK or NO
42+
if OK
43+
CLIENT: SEND FILE
44+
SERVER: OK
45+
else
46+
CLIENT: OK
47+
SERVER: SEND FILE
48+
CLIENT: OK
49+
SERVER: SEND LAST MODIFIED
50+
end
51+
end
52+
53+
CLIENT: DONE
54+
55+
if EXISTS
56+
if directory
57+
SERVER: dirName DiR
58+
CLIENT: OK or NO
59+
if NO
60+
SERVER: OK
61+
CLIENT: ask user if he/she would like to delete servers copy
62+
reply YE (delete) or NO (get servers copy)
63+
or DN (do nothing)
64+
if YE
65+
SERVER: delete directory
66+
if NO
67+
CLIENT: make directory
68+
if DN
69+
do nothing
70+
end
71+
end
72+
else
73+
SERVER: fileName
74+
CLIENT: OK or NO
75+
if NO
76+
SERVER: OK
77+
CLIENT: ask user if he/she would like to delete servers copy
78+
reply YE (delete) or NO (get servers copy)
79+
or DN (do nothing)
80+
if YE
81+
SERVER: delete file
82+
if NO
83+
SERVER: SEND FILE
84+
CLIENT: OK
85+
SERVER: SEND LASTMODIFIED
86+
CLIENT: OK
87+
if DN
88+
do nothing
89+
end
90+
end
91+
end
92+
end
93+

src/net/quaa/jfs/Client.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.quaa.jfs;
22

3+
import java.io.File;
4+
import java.io.ObjectInputStream;
35
import java.io.ObjectOutputStream;
46
import java.net.Socket;
57

@@ -44,10 +46,19 @@ public void runClient() throws Exception {
4446
}
4547

4648
Socket sock = new Socket(serverIP, PORT_NUMBER);
47-
ObjectOutputStream oos = new ObjectOutputStream(sock.getOutputStream());
49+
ObjectOutputStream oos = new ObjectOutputStream(sock.getOutputStream()); // send directory name to server
4850
oos.writeObject(localDirName);
4951
oos.flush();
5052

53+
ObjectInputStream ois = new ObjectInputStream(sock.getInputStream()); // receive if this directory exists
54+
String fExists = (String) ois.readObject();
55+
56+
visitAllDirsAndFiles(new File(dirName), sock);
57+
58+
if(fExists.equals("EXISTS")) {
59+
updateFromServer(sock);
60+
}
61+
5162
/* //check to see if file exists on server
5263
ObjectInputStream ois = new ObjectInputStream(sock.getInputStream());
5364
String fExists = (String) ois.readObject();
@@ -74,6 +85,23 @@ public void runClient() throws Exception {
7485
System.out.println("Server replied that " + fileName + " does not exist, closing connection.");
7586
}
7687
*/ oos.close();
88+
ois.close();
7789
sock.close();
7890
}
91+
92+
// Process all files and directories under dir
93+
public static void visitAllDirsAndFiles(File dir, Socket sock) {
94+
// DO WORK HERE
95+
System.out.println("Name: " + dir.getName() + " Modified: " + dir.lastModified() + " Size: " + dir.length());
96+
if (dir.isDirectory()) {
97+
String[] children = dir.list();
98+
for (int i=0; i<children.length; i++) {
99+
visitAllDirsAndFiles(new File(dir, children[i]), sock);
100+
}
101+
}
102+
}
103+
104+
public static void updateFromServer(Socket sock) {
105+
106+
}
79107
}

0 commit comments

Comments
 (0)