-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.java
More file actions
147 lines (117 loc) · 4.35 KB
/
Copy pathserver.java
File metadata and controls
147 lines (117 loc) · 4.35 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.*;
import java.util.Vector;
import javax.swing.*;
public class server extends JFrame implements ActionListener, Runnable {
Socket socket;
server() {
setLayout(null);
JPanel p1 = new JPanel();
p1.setLayout(null);
p1.setBackground(new Color(7,94,84));
p1.setBounds(0,0,500,70);
add(p1);
//back button
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icons/3.png"));
Image i2 = i1.getImage().getScaledInstance(30,30,Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
JLabel back = new JLabel(i3);
back.setBounds(5,20,30,30);
p1.add(back);
back.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent ae){
System.exit(0);
}
});
//profile image
ImageIcon i4 = new ImageIcon(ClassLoader.getSystemResource("icons/1.png"));
Image i5 = i4.getImage().getScaledInstance(50,50,Image.SCALE_DEFAULT);
ImageIcon i6 = new ImageIcon(i5);
JLabel profile = new JLabel(i6);
profile.setBounds(40,10,50,50);
p1.add(profile);
//video call icon
ImageIcon i7Icon = new ImageIcon(ClassLoader.getSystemResource("icons/video.png"));
Image i8 = i7Icon.getImage().getScaledInstance(50,50,Image.SCALE_DEFAULT);
ImageIcon i9 = new ImageIcon(i8);
JLabel video = new JLabel(i9);
video.setBounds(400,20,30,30);
p1.add(video);
//telephone icon
ImageIcon i10Icon = new ImageIcon(ClassLoader.getSystemResource("icons/phone.png"));
Image i = i10Icon.getImage().getScaledInstance(50,50,Image.SCALE_DEFAULT);
ImageIcon i11 = new ImageIcon(i);
JLabel telephone = new JLabel(i11);
telephone.setBounds(450,20,30,30);
p1.add(telephone);
//name label
JLabel name = new JLabel("Garv");
name.setFont(new Font("SAN_SERIF",Font.BOLD,18));
name.setForeground(Color.WHITE);
name.setBounds(100,15,100,20);
p1.add(name);
//text
JTextField text = new JTextField();
text.setBounds(5,600,350,40);
text.setFont(new Font("SAN_SERIF",Font.PLAIN,16));
add(text);
//send button
JButton send = new JButton("Send");
send.setBounds(360,600,120,40);
send.setBackground(new Color(7,94,84));
send.setForeground(Color.WHITE);
send.setFont(new Font("SAN_SERIF",Font.PLAIN,16));
add(send);
setSize(500,700);
setVisible(true);
setLocation(500,200);
getContentPane().setBackground(Color.WHITE);
}
public static Vector clients = new Vector();
public server (Socket socket){
try {
this.socket=socket;
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
try {
BufferedReader br =new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
clients.add(writer);
while (true) {
String data = br.readLine().trim();
System.out.println("recieved"+data);
for(int i=0;i<clients.size();i++){
try {
BufferedWriter bw = (BufferedWriter)clients.get(i);
bw.write(data);
bw.write("\r\n");
bw.flush();
} catch (Exception e) {
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent ae) {
}
public static void main(String[] args) throws Exception{
new server();
ServerSocket a = new ServerSocket(6001);
while(true){
Socket socket = a.accept();
server s = new server(socket);
Thread t = new Thread(s);
t.start();
}
}
}