diff --git a/JChatClient/bin/client b/JChatClient/bin/client index 1d67a21..fa671a2 100755 --- a/JChatClient/bin/client +++ b/JChatClient/bin/client diff --git a/JChatClient/src/client.cpp b/JChatClient/src/client.cpp index 774c5a4..aac1016 100644 --- a/JChatClient/src/client.cpp +++ b/JChatClient/src/client.cpp @@ -71,7 +71,8 @@ bool connect(Socket& s) while(response == "CHATFULL") { cout << "Chatroom is full, please wait..." << endl; - s >> response; + s.Close(); + return false; } if(response != "CHATOK") { @@ -172,11 +173,17 @@ int main() pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); + int retries = 3; while (!finished) { - if(!connect(s)) + while(!connect(s)) { - exit(-1); + if((--retries) <= 0) + { + cout << "Exiting" << endl; + exit(-1); + } + cout << "Couldn't connect to chatroom, retrying..." << endl; } pthread_mutex_lock(&mutex); sArgs->mutex = &mutex; diff --git a/JChatServer/bin/pad/prac2/JChat.class b/JChatServer/bin/pad/prac2/JChat.class index 334e93d..4eb79da 100644 --- a/JChatServer/bin/pad/prac2/JChat.class +++ b/JChatServer/bin/pad/prac2/JChat.class diff --git a/JChatServer/bin/pad/prac2/Server.class b/JChatServer/bin/pad/prac2/Server.class index 5832f85..a6de29a 100644 --- a/JChatServer/bin/pad/prac2/Server.class +++ b/JChatServer/bin/pad/prac2/Server.class diff --git a/JChatServer/src/pad/prac2/JChat.java b/JChatServer/src/pad/prac2/JChat.java index 2455693..1e794d2 100644 --- a/JChatServer/src/pad/prac2/JChat.java +++ b/JChatServer/src/pad/prac2/JChat.java @@ -19,7 +19,7 @@ public class JChat in.close();*/ ip = "localhost"; port = 3001; - roomSize = 3; + roomSize = 2; final Server serv = new Server(ip,port,roomSize); Runtime.getRuntime().addShutdownHook(new Thread() { @@ -34,6 +34,7 @@ public class JChat /* * TODO * + * room is full * CTRL+C */ } diff --git a/JChatServer/src/pad/prac2/Server.java b/JChatServer/src/pad/prac2/Server.java index a77c45d..4d860de 100644 --- a/JChatServer/src/pad/prac2/Server.java +++ b/JChatServer/src/pad/prac2/Server.java @@ -52,7 +52,6 @@ public class Server try { MySocket incoming = ss.accept(); - System.out.println("Accepted connection from " + incoming.getInetAddress()); startWorker(incoming); } catch(IOException ioExc) @@ -75,14 +74,9 @@ public class Server try { s.sendMsg("CHATFULL"); - synchronized(this) - { - availableWorkers.await(); - } - } - catch(InterruptedException intExc) - { - intExc.printStackTrace(); + s.close(); + lock.unlock(); + return; } catch(IOException ioExc) {