Commit 9256c58b2a329ecfc0aa6100335cd6a3d9b20500
1 parent
77176d9b
git-svn-id: svn://imanolbarba.net/PAD@28 c2ee353e-ed0d-4329-bf56-03aec153487f
Showing
6 changed files
with
15 additions
and
13 deletions
JChatClient/bin/client
No preview for this file type
JChatClient/src/client.cpp
... | ... | @@ -71,7 +71,8 @@ bool connect(Socket& s) |
71 | 71 | while(response == "CHATFULL") |
72 | 72 | { |
73 | 73 | cout << "Chatroom is full, please wait..." << endl; |
74 | - s >> response; | |
74 | + s.Close(); | |
75 | + return false; | |
75 | 76 | } |
76 | 77 | if(response != "CHATOK") |
77 | 78 | { |
... | ... | @@ -172,11 +173,17 @@ int main() |
172 | 173 | pthread_attr_t attr; |
173 | 174 | pthread_attr_init(&attr); |
174 | 175 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); |
176 | + int retries = 3; | |
175 | 177 | while (!finished) |
176 | 178 | { |
177 | - if(!connect(s)) | |
179 | + while(!connect(s)) | |
178 | 180 | { |
179 | - exit(-1); | |
181 | + if((--retries) <= 0) | |
182 | + { | |
183 | + cout << "Exiting" << endl; | |
184 | + exit(-1); | |
185 | + } | |
186 | + cout << "Couldn't connect to chatroom, retrying..." << endl; | |
180 | 187 | } |
181 | 188 | pthread_mutex_lock(&mutex); |
182 | 189 | sArgs->mutex = &mutex; | ... | ... |
JChatServer/bin/pad/prac2/JChat.class
No preview for this file type
JChatServer/bin/pad/prac2/Server.class
No preview for this file type
JChatServer/src/pad/prac2/JChat.java
... | ... | @@ -19,7 +19,7 @@ public class JChat |
19 | 19 | in.close();*/ |
20 | 20 | ip = "localhost"; |
21 | 21 | port = 3001; |
22 | - roomSize = 3; | |
22 | + roomSize = 2; | |
23 | 23 | final Server serv = new Server(ip,port,roomSize); |
24 | 24 | Runtime.getRuntime().addShutdownHook(new Thread() |
25 | 25 | { |
... | ... | @@ -34,6 +34,7 @@ public class JChat |
34 | 34 | /* |
35 | 35 | * TODO |
36 | 36 | * |
37 | + * room is full | |
37 | 38 | * CTRL+C |
38 | 39 | */ |
39 | 40 | } | ... | ... |
JChatServer/src/pad/prac2/Server.java
... | ... | @@ -52,7 +52,6 @@ public class Server |
52 | 52 | try |
53 | 53 | { |
54 | 54 | MySocket incoming = ss.accept(); |
55 | - System.out.println("Accepted connection from " + incoming.getInetAddress()); | |
56 | 55 | startWorker(incoming); |
57 | 56 | } |
58 | 57 | catch(IOException ioExc) |
... | ... | @@ -75,14 +74,9 @@ public class Server |
75 | 74 | try |
76 | 75 | { |
77 | 76 | s.sendMsg("CHATFULL"); |
78 | - synchronized(this) | |
79 | - { | |
80 | - availableWorkers.await(); | |
81 | - } | |
82 | - } | |
83 | - catch(InterruptedException intExc) | |
84 | - { | |
85 | - intExc.printStackTrace(); | |
77 | + s.close(); | |
78 | + lock.unlock(); | |
79 | + return; | |
86 | 80 | } |
87 | 81 | catch(IOException ioExc) |
88 | 82 | { | ... | ... |