|
@@ -1,5 +1,10 @@
|
|
1
|
+import java.io.BufferedReader;
|
1
|
2
|
import java.io.IOException;
|
|
3
|
+import java.io.InputStreamReader;
|
|
4
|
+import java.io.PrintWriter;
|
2
|
5
|
import java.net.*;
|
|
6
|
+import java.text.DateFormat;
|
|
7
|
+import java.text.SimpleDateFormat;
|
3
|
8
|
import java.util.Date;
|
4
|
9
|
import java.util.Scanner; // Import the Scanner class
|
5
|
10
|
import java.util.ArrayList; // import the ArrayList class
|
|
@@ -119,6 +124,9 @@ public class User{
|
119
|
124
|
* Demande à l'utilisateur de rentrer un pseudo et validation de ce dernier en demandant aux utilisateurs distants leurs informations
|
120
|
125
|
* On regarde si le pseudo est bien différent de l'ancien
|
121
|
126
|
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
122
|
130
|
private void setPseudo() throws IOException {
|
123
|
131
|
String oldPseudo = this.pseudo; //Saves the old one for comparison
|
124
|
132
|
|
|
@@ -161,6 +169,53 @@ public class User{
|
161
|
169
|
System.out.println("Your nickname : " + tmpPseudo + " is valid !");
|
162
|
170
|
}
|
163
|
171
|
|
|
172
|
+ public void TCPmessage(int index) throws IOException {
|
|
173
|
+ Socket link=null;
|
|
174
|
+ try {
|
|
175
|
+ link=new Socket(this.userChatList.get(index).addIP,this.portTCP);
|
|
176
|
+
|
|
177
|
+ System.out.println("Server is listening on port"+this.portTCP+"of localhost");
|
|
178
|
+ }catch(IOException e) {
|
|
179
|
+
|
|
180
|
+ System.out.println("Server is not listening on port"+this.portTCP+" of localhost");
|
|
181
|
+
|
|
182
|
+ }
|
|
183
|
+ BufferedReader in=null;
|
|
184
|
+ try {
|
|
185
|
+ in = new BufferedReader(new InputStreamReader(link.getInputStream()));
|
|
186
|
+ } catch (IOException e) {
|
|
187
|
+ // TODO Auto-generated catch block
|
|
188
|
+ e.printStackTrace();
|
|
189
|
+ }
|
|
190
|
+ try {
|
|
191
|
+ PrintWriter out = new PrintWriter(link.getOutputStream(),true);
|
|
192
|
+ } catch (IOException e) {
|
|
193
|
+ // TODO Auto-generated catch block
|
|
194
|
+ e.printStackTrace();
|
|
195
|
+ }
|
|
196
|
+ String input;
|
|
197
|
+ try {
|
|
198
|
+ while (!(input=in.readLine()).equals("end")) {
|
|
199
|
+ System.out.print("client_recoit:"+input);
|
|
200
|
+ }
|
|
201
|
+ } catch (IOException e) {
|
|
202
|
+ // TODO Auto-generated catch block
|
|
203
|
+ e.printStackTrace();
|
|
204
|
+ }
|
|
205
|
+ /*or (int i=0; i<4; i++) {
|
|
206
|
+ System.out.println("client envoie");
|
|
207
|
+ out.println("coucou \n");
|
|
208
|
+ }
|
|
209
|
+ out.println("end");*/
|
|
210
|
+ try {
|
|
211
|
+ link.close();
|
|
212
|
+ } catch (IOException e) {
|
|
213
|
+ // TODO Auto-generated catch block
|
|
214
|
+ e.printStackTrace();
|
|
215
|
+ }
|
|
216
|
+ }
|
|
217
|
+
|
|
218
|
+
|
164
|
219
|
/* validatePseudo
|
165
|
220
|
* $parametres
|
166
|
221
|
* *tmpPseudo : String => Le pseudo à valider
|
|
@@ -342,7 +397,7 @@ public class User{
|
342
|
397
|
* $description
|
343
|
398
|
* Laisse l'utilisateur choisir parmis la liste d'utilisateur actif celui avec lequel il souhaite échangé via un chat
|
344
|
399
|
*/
|
345
|
|
- public void getOneActiveUser() throws UnknownHostException {
|
|
400
|
+ public void getOneActiveUser() throws IOException {
|
346
|
401
|
this.printRemoteUserList();
|
347
|
402
|
Scanner sc2= new Scanner(System.in);
|
348
|
403
|
System.out.println("Please, enter index of one active user that you saw on the list to start a conversation with:");
|
|
@@ -360,6 +415,8 @@ public class User{
|
360
|
415
|
else {
|
361
|
416
|
System.out.println("Wrong index (no active at index number "+index+" )");
|
362
|
417
|
}
|
|
418
|
+
|
|
419
|
+ this.TCPmessage(index);
|
363
|
420
|
//sc2.close();
|
364
|
421
|
}
|
365
|
422
|
|
|
@@ -378,6 +435,9 @@ public class User{
|
378
|
435
|
System.out.println("Sleep mode for 5 seconds");
|
379
|
436
|
Thread.sleep(5000);
|
380
|
437
|
// On ferme les différents threads et socket d'écoute
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
381
|
441
|
usr1.threadListeningUDP.close();
|
382
|
442
|
usr2.threadListeningUDP.close();
|
383
|
443
|
usr3.threadListeningUDP.close();
|