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, should be setable
8 private String randName
;
10 ThreadClientoSend(SocketClient c
) {
12 randName
= randomName();
15 private String
randomName() {
17 int leftLimit
= 97; // letter 'a'
18 int rightLimit
= 122; // letter 'z'
19 int targetStringLength
= 8;
20 Random random
= new Random();
21 StringBuilder buffer
= new StringBuilder(targetStringLength
);
22 for (int i
= 0; i
< targetStringLength
; i
++) {
23 int randomLimitedInt
= leftLimit
+ (int)(random
.nextFloat() * (rightLimit
- leftLimit
+ 1));
24 buffer
.append((char)randomLimitedInt
);
26 String generatedString
= buffer
.toString();
28 return generatedString
;
32 BufferedReader userInput
= null;
34 userInput
= new BufferedReader(new InputStreamReader(System
.in
));
37 String line
= userInput
.readLine();
38 if (line
.equals(".")) {
41 Message oMsg
= new Message(randName
, line
, Calendar
.getInstance());
42 client
.sendoMsg(oMsg
);
43 System
.out
.println(Thread
.currentThread().getName() + " a envoye " + oMsg
);
46 catch (IOException e
) {
47 System
.err
.println("IOException: " + e
);
51 if (userInput
!= null) {
55 catch (IOException e
) {
56 System
.err
.println("IOException: " + e
);