From 9256c58b2a329ecfc0aa6100335cd6a3d9b20500 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Tue, 10 Dec 2013 01:26:01 +0000 Subject: [PATCH] git-svn-id: svn://imanolbarba.net/PAD@28 c2ee353e-ed0d-4329-bf56-03aec153487f --- JChatClient/bin/client | Bin 23296 -> 0 bytes JChatClient/src/client.cpp | 13 ++++++++++--- JChatServer/bin/pad/prac2/JChat.class | Bin 866 -> 0 bytes JChatServer/bin/pad/prac2/Server.class | Bin 6672 -> 0 bytes JChatServer/src/pad/prac2/JChat.java | 3 ++- JChatServer/src/pad/prac2/Server.java | 12 +++--------- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/JChatClient/bin/client b/JChatClient/bin/client index 1d67a21..fa671a2 100755 Binary files a/JChatClient/bin/client and b/JChatClient/bin/client differ 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 Binary files a/JChatServer/bin/pad/prac2/JChat.class and b/JChatServer/bin/pad/prac2/JChat.class differ diff --git a/JChatServer/bin/pad/prac2/Server.class b/JChatServer/bin/pad/prac2/Server.class index 5832f85..a6de29a 100644 Binary files a/JChatServer/bin/pad/prac2/Server.class and b/JChatServer/bin/pad/prac2/Server.class differ 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) { -- libgit2 0.22.2