88import java .io .ObjectOutputStream ;
99import java .net .ServerSocket ;
1010import java .net .Socket ;
11+ import java .util .Vector ;
1112
1213public class Server {
1314 private int PORT_NUMBER ;
@@ -27,6 +28,7 @@ public void startServer() throws Exception {
2728 servsock = new ServerSocket (PORT_NUMBER );
2829
2930 while (true ) {
31+ System .out .println ("NEW CLIENT" );
3032 sock = servsock .accept ();
3133
3234 ois = new ObjectInputStream (sock .getInputStream ());
@@ -46,7 +48,7 @@ public void startServer() throws Exception {
4648 Boolean isClientDone = false ;
4749
4850 while (!isClientDone ) {
49- String fName = (String ) ois .readObject ();
51+ /* String fName = (String) ois.readObject();
5052
5153 if(fName.equals(DONE)) { // check if we are done
5254 isClientDone = true;
@@ -57,21 +59,36 @@ public void startServer() throws Exception {
5759 oos.flush();
5860
5961 Boolean isDirectory = (Boolean) ois.readObject();
62+ */
63+ Vector <String > vec = (Vector <String >) ois .readObject ();
6064
61- if (isDirectory ) {
62- oos .writeObject (new Boolean (true ));
65+ oos .close ();
66+ ois .close ();
67+ sock .close ();
68+ sock = servsock .accept ();
69+ oos = new ObjectOutputStream (sock .getOutputStream ());
70+ ois = new ObjectInputStream (sock .getInputStream ());
71+ System .out .println (vec .elementAt (0 ));
72+ if (vec .elementAt (0 ).equals (DONE )) {
73+ System .out .println (DONE );
74+ isClientDone = true ;
75+ break ;
76+ }
77+
78+ if (vec .size () == 2 ) { // if the size is 2 then this is a directory
79+ /* oos.writeObject(new Boolean(true));
6380 oos.flush();
6481
6582 String path = (String) ois.readObject();
66-
67- File newDir = new File (baseDir , path );
83+ */
84+ File newDir = new File (baseDir , vec . elementAt ( 1 ) );
6885 if (!newDir .exists ())
6986 newDir .mkdir ();
7087
7188 oos .writeObject (new Boolean (true ));
7289 oos .flush ();
7390 } else {
74- oos .writeObject (new Boolean (true ));
91+ /* oos.writeObject(new Boolean(true));
7592 oos.flush();
7693
7794 String path = (String) ois.readObject();
@@ -80,10 +97,11 @@ public void startServer() throws Exception {
8097 oos.flush();
8198
8299 Long lastModified = (Long) ois.readObject();
83-
84- File newFile = new File (baseDir , path );
100+ */
101+ File newFile = new File (baseDir , vec . elementAt ( 1 ) );
85102 Integer updateFromClient = 2 ; // default = do nothing
86103
104+ Long lastModified = new Long (vec .elementAt (2 ));
87105 if (!newFile .exists () || (newFile .lastModified () <= lastModified ))
88106 updateFromClient = 1 ;
89107 else
0 commit comments