2 import java
.util
.Calendar
;
3 import java
.util
.Random
;
5 public class ThreadClientoSend
implements Runnable
{
6 private SocketClient client
;
7 //FIXME: use a random name by thread for now
9 private String randName
;
11 ThreadClientoSend(SocketClient c
) {
13 randName
= randomName();
16 private String
randomName() {
18 int leftLimit
= 97; // letter 'a'
19 int rightLimit
= 122; // letter 'z'
20 int targetStringLength
= 8;
21 Random random
= new Random();
22 StringBuilder buffer
= new StringBuilder(targetStringLength
);
23 for (int i
= 0; i
< targetStringLength
; i
++) {
24 int randomLimitedInt
= leftLimit
+ (int)(random
.nextFloat() * (rightLimit
- leftLimit
+ 1));
25 buffer
.append((char)randomLimitedInt
);
27 String generatedString
= buffer
.toString();
29 return generatedString
;
33 BufferedReader userInput
= null;
35 userInput
= new BufferedReader(new InputStreamReader(System
.in
));
38 String line
= userInput
.readLine();
39 if (line
.equals(".")) {
42 Message oMsg
= new Message(randName
, line
, Calendar
.getInstance());
43 client
.sendoMsg(oMsg
);
44 System
.out
.println(Thread
.currentThread().getName() + " a envoye " + oMsg
);
47 catch (IOException e
) {
48 System
.err
.println("IOException: " + e
);
52 if (userInput
!= null) {
56 catch (IOException e
) {
57 System
.err
.println("IOException: " + e
);