-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser2.java
More file actions
75 lines (64 loc) · 1.84 KB
/
user2.java
File metadata and controls
75 lines (64 loc) · 1.84 KB
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
70
71
72
73
74
75
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import java.io.DataOutputStream;
import java.io.DataInputStream;
public class user2 extends Frame implements Runnable,ActionListener{
TextField tf;
TextArea ta;
Button send;
ServerSocket sc;
Socket s;
DataInputStream di;
DataOutputStream dd;
Thread c;
user2(){
tf=new TextField();
ta=new TextArea();
send=new Button("send");
send.addActionListener(this);
try{
sc =new ServerSocket(12000);
s=sc.accept();
di=new DataInputStream(s.getInputStream());
dd=new DataOutputStream(s.getOutputStream());
}
catch(Exception e){
}
add(tf);
add(ta);
add(send);
c=new Thread(this);
c.setDaemon(true);
c.start();
setSize(500,500);
setTitle("user2");
setLayout(new FlowLayout());
setVisible(true);
}
public void actionPerformed(ActionEvent e){
String msg=tf.getText();
ta.append("uesr2:"+msg+"\n");
tf.setText("");
try{
dd.writeUTF(msg);
dd.flush();
}
catch(Exception ex){
}
}
public static void main(String[] args){
new user2();
}
public void run(){
while(true){
try{
String msg= di.readUTF();
ta.append("user1:"+msg+"\n");
}
catch(Exception e){
}
}
}
}