|
Tips & Tricks |
|
class My1 implements Runnable{
DataOutputStream dout1;
DefaultListModel model1;
DataInputStream din1;
String name,lname;
ArrayList alname=new ArrayList();
ObjectInputStream obj;
int i=0;
My1(DataOutputStream
dout1,DefaultListModel model1,
String name,DataInputStream din1){
this.dout1=dout1;
this.model1=model1;
this.name=name;
this.din1=din1;
}
public void run(){
try{
// write the user name in output
stream
dout1.writeUTF(name);
while(true){
obj=new ObjectInputStream(din1);
//read the list of user names
alname=(ArrayList)obj.readObject();
if(i>0)
model1.clear();
Iterator i1=alname.iterator();
System.out.println(alname);
while(i1.hasNext()){
lname=(String)i1.next();
i++;
//add the user names in list box
model1.addElement(lname);
}
}
}catch(Exception oe){}
}
|
|
}
//class is used to receive message
class My implements Runnable{
DataInputStream din;
DefaultListModel model;
My(DataInputStream din, DefaultListModel
model){
this.din=din;
this.model=model;
}
public void run(){
String str1=””;
while(true){
try{
str1=din.readUTF(); // receive the
message
// add the message in list box
model.addElement(str1);
}catch(Exception e){}
}
}
}
Server side application
Server side application is used to get the message from any client and broadcast to each
and every client. And this application is also
used to maintain the list of users and broadcast
this list to everyone.
|
|
Nov
2007 | Java Jazz Up |63 |
|
|
View All Topics |
All Pages of this Issue |
Pages:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63 ,
64,
65 ,
66 ,
67 ,
68 ,
69 Download PDF |
|
|
|
|
|
|
|
|
|