-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.java
639 lines (568 loc) · 24.7 KB
/
Client.java
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.net.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.awt.image.BufferedImage;
//import javax.swing.event.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.awt.event.*;
import java.awt.*;
import com.github.sarxos.webcam.*; // for geting webcam Videos
class Client extends JFrame {
static String IP_ADDRESS_STRING = "localhost";
static int PORT = 2000;
static String CURRENT_USER = "Client";
static String PASSWORD = "1234"; // FOR TESTING PURPOSES
static boolean isSetupDone;
static boolean runCam;
static Socket videoSocket;
static Socket audioSocket;
static JFrame videoFrame = new JFrame();
static final int VIDEO_HEIGHT = 320, VIDEO_WIDTH = 240;
static Encryption enc = new Encryption();
static Decryption dec = new Decryption();
/**
*
*/
private static final long serialVersionUID = 1L;
Socket clientSocket;
JLabel groupName;
JButton send, fileSend, videoStream;
JTextField msg;
JPanel chat;
JScrollPane scrollPane;
JFileChooser jfc;
static {
loginInterface();
}
private static void loginInterface() {
Client.isSetupDone = false;
JLabel nameLabel, ipLabel, portLabel, passwordLabel;
JTextField nameTextField, ipTextField, portTextField;
JPasswordField passwordTextField;
JButton connect;
JFrame frame = new JFrame();
frame.setTitle("Set-UP");
nameLabel = new JLabel(" Name :");
ipLabel = new JLabel("IP Address :");
passwordLabel = new JLabel(" Password :");
portLabel = new JLabel(" Port :");
nameTextField = new JTextField(15);
ipTextField = new JTextField(15);
portTextField = new JTextField(15);
passwordTextField = new JPasswordField(15);
connect = new JButton("Connect !");
ipTextField.setText("localhost");
portTextField.setText(PORT + "");
Container contentPane = frame.getContentPane();
SpringLayout layout = new SpringLayout();
contentPane.setLayout(layout);
contentPane.add(nameLabel);
contentPane.add(nameTextField);
contentPane.add(ipLabel);
contentPane.add(ipTextField);
contentPane.add(portLabel);
contentPane.add(portTextField);
contentPane.add(passwordLabel);
contentPane.add(passwordTextField);
contentPane.add(connect);
// Name
layout.putConstraint(SpringLayout.WEST, nameLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, nameLabel, 5, SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.WEST, nameTextField, 5, SpringLayout.EAST, nameLabel);
layout.putConstraint(SpringLayout.NORTH, nameTextField, 5, SpringLayout.NORTH, contentPane);
// IP Address
layout.putConstraint(SpringLayout.WEST, ipLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, ipLabel, 5, SpringLayout.SOUTH, nameTextField);
layout.putConstraint(SpringLayout.WEST, ipTextField, 5, SpringLayout.EAST, ipLabel);
layout.putConstraint(SpringLayout.NORTH, ipTextField, 5, SpringLayout.SOUTH, nameTextField);
// Port
layout.putConstraint(SpringLayout.WEST, portLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, portLabel, 5, SpringLayout.SOUTH, ipTextField);
layout.putConstraint(SpringLayout.WEST, portTextField, 5, SpringLayout.EAST, portLabel);
layout.putConstraint(SpringLayout.NORTH, portTextField, 5, SpringLayout.SOUTH, ipTextField);
// Password
layout.putConstraint(SpringLayout.WEST, passwordLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, passwordLabel, 5, SpringLayout.SOUTH, portTextField);
layout.putConstraint(SpringLayout.WEST, passwordTextField, 5, SpringLayout.EAST, passwordLabel);
layout.putConstraint(SpringLayout.NORTH, passwordTextField, 5, SpringLayout.SOUTH, portTextField);
// Connect Button
layout.putConstraint(SpringLayout.WEST, connect, 5, SpringLayout.EAST, portLabel);
layout.putConstraint(SpringLayout.NORTH, connect, 5, SpringLayout.SOUTH, passwordTextField);
// Boundries
layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, portTextField);
layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, connect);
frame.pack();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
connect.addActionListener(
e -> ConnectToServer(nameTextField, ipTextField, portTextField, passwordTextField, frame));
passwordTextField.addActionListener(
e -> ConnectToServer(nameTextField, ipTextField, portTextField, passwordTextField, frame));
}
private static void ConnectToServer(JTextField nameTextField, JTextField ipTextField, JTextField portTextField,
JPasswordField passwordTextField, JFrame frame) {
if (nameTextField.getText().toString().isBlank() || ipTextField.getText().toString().isBlank()
|| new String(passwordTextField.getPassword()).isBlank()
|| portTextField.getText().toString().isBlank()) {
String tPass = ((new String(passwordTextField.getPassword())).isBlank()) ? " Password Field" : "";
String tName = (nameTextField.getText().toString().isBlank()) ? "Name Field" : "";
JOptionPane.showMessageDialog(null, tName + tPass + " cannot be Empty", "Note",
JOptionPane.INFORMATION_MESSAGE);
} else {
// System.out.println("Vrtified ...");
CURRENT_USER = nameTextField.getText().toString();
IP_ADDRESS_STRING = ipTextField.getText().toString();
PORT = Integer.parseInt(portTextField.getText().toString());
PASSWORD = new String(passwordTextField.getPassword());
Client.isSetupDone = true;
frame.dispose();
}
}
Client() {
super("Chat Window:Client");
setLayout(new BorderLayout());
setUI();
setSize(400, 550);
setVisible(true);
setDefaultCloseOperation(3);
listeners();
}
private void listeners() {
send.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
if (msg.getText() == null || msg.getText().toString().trim().length() == 0) {
} else {
String content = msg.getText().toString();
msg.setText("");
DataOutputStream dout = new DataOutputStream(clientSocket.getOutputStream());
dout.writeUTF(Client.CURRENT_USER + ":::" + Client.enc.encrypt(content, Client.PASSWORD));
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
msg.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
if (msg.getText() == null || msg.getText().toString().trim().length() == 0) {
} else {
String content = msg.getText().toString();
msg.setText("");
DataOutputStream dout = new DataOutputStream(clientSocket.getOutputStream());
dout.writeUTF(Client.CURRENT_USER + ":::" + Client.enc.encrypt(content, Client.PASSWORD));
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
try {
DataOutputStream dout = new DataOutputStream(clientSocket.getOutputStream()); // sendign
dout.writeUTF("GRP_INFO" + ":::" + Client.CURRENT_USER + " left the Chat.");
dout.writeUTF("END");
ObjectOutputStream oout = new ObjectOutputStream(videoSocket.getOutputStream());
oout.writeObject(new ImageIcon("images\\endImage.png", "END"));
} catch (Exception e) {
System.out.println(e);
}
}
});
fileSend.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
jfc.showOpenDialog(null);
if (jfc.getSelectedFile() != null) {
/*
* //To send Text Data Alone String s1 = "FILE_TRANS:::"; while ((b = (byte)
* din.read()) != -1) { s1 += (char) b; } din.close(); DataOutputStream dout =
* new DataOutputStream(clientSocket.getOutputStream()); dout.writeUTF(s1 +
* ":::" + jfc.getSelectedFile().getName() + ":::" + Client.CURRENT_USER);
*
* System.out.println(s1 + ":::" + jfc.getSelectedFile().getName() + ":::" +
* Client.CURRENT_USER);
*/
/*
* DataInputStream din = new DataInputStream(new
* FileInputStream(jfc.getSelectedFile())); DataOutputStream dout = new
* DataOutputStream(clientSocket.getOutputStream());
*/
File file = jfc.getSelectedFile();
FileInputStream fis = new FileInputStream(file.getPath());
int fileLen = (int) file.length();
String transferINFO = "FILE_TRANS:::" + file.getName() + ":::" + fileLen + ":::"
+ Client.CURRENT_USER;
DataOutputStream dos = new DataOutputStream(clientSocket.getOutputStream());
dos.writeUTF(transferINFO);
byte b[] = new byte[fileLen];
fis.read(b, 0, b.length);
fis.close();
dos.write(b, 0, b.length);
dos.flush();
addMessages("GRP_INFO", "You Send A File");
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
videoStream.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Webcam cam = Webcam.getDefault();
Client.runCam = true;
cam.setViewSize(new Dimension(Client.VIDEO_HEIGHT, Client.VIDEO_WIDTH));
try {
ImageIcon ic = null;
BufferedImage br = null;
ObjectOutputStream vstream = new ObjectOutputStream(Client.videoSocket.getOutputStream());
cam.open();
new VideoOutstreamThread(ic, br, vstream, cam).start();
new AudioOutStreamThread().start();
} catch (Exception exception) {
exception.printStackTrace();
}
videoStreamStopUI();
}
});
}
void videoStreamStopUI() {
JFrame stopFrame = new JFrame();
stopFrame.setTitle("Pack()");
stopFrame.setLayout(new FlowLayout());
JButton stopButton = new JButton("Stop");
stopFrame.add(stopButton);
stopFrame.pack(); // calling the pack() method
stopFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
stopFrame.setLocationRelativeTo(null);
stopFrame.setVisible(true);
stopButton.addActionListener(ae -> {
Client.runCam = false;
stopFrame.dispose();
});
stopFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
Client.runCam = false;
stopFrame.dispose();
}
});
}
private void setUI() {
// initila UI setup
groupName = new JLabel("Connecting...");
send = new JButton();
fileSend = new JButton();
videoStream = new JButton();
videoStream.setIcon(new ImageIcon("images\\videoicon.png"));
send.setIcon(new ImageIcon("images\\sendicon.png"));
fileSend.setIcon(new ImageIcon("images\\ftpicon.png"));
fileSend.setToolTipText("File Transfer");
videoStream.setToolTipText("Video Stream");
send.setToolTipText("Send");
msg = new JTextField(25);
chat = new JPanel();
scrollPane = new JScrollPane(chat);
jfc = new JFileChooser();
// NORTH
JPanel top = new JPanel();
top.setLayout(new FlowLayout(FlowLayout.CENTER));
add(top, BorderLayout.NORTH);
top.add(groupName);
// CENTER
add(scrollPane, BorderLayout.CENTER);
// chat.setLayout(new BoxLayout(chat , BoxLayout.Y_AXIS));
// scrollPane.setBorder(new EmptyBorder(10, 10, 10, 10));
chat.setLayout(new BorderLayout());
// SOUTH
JPanel p1 = new JPanel(new BorderLayout());
JPanel p2 = new JPanel(new BorderLayout());
JPanel p3 = new JPanel(new BorderLayout());
add(p1, BorderLayout.SOUTH);
p1.add(p2, BorderLayout.CENTER);
p1.add(send, BorderLayout.EAST);
p1.setBorder(new EmptyBorder(10, 10, 10, 10));
p2.add(p3, BorderLayout.CENTER);
p2.add(fileSend, BorderLayout.EAST);
p3.add(msg, BorderLayout.CENTER);
p3.add(videoStream, BorderLayout.EAST);
}
private void handleFileTransfer(String fileName, String fileLen, String sender, DataInputStream din) {
try {
File directory = new File("FTP Recieved");
if (!directory.exists())
directory.mkdir();
int len = Integer.parseInt(fileLen);
FileOutputStream fout = new FileOutputStream("FTP Recieved\\" + fileName);
byte bytes[] = new byte[len];
din.readFully(bytes, 0, bytes.length);
fout.write(bytes, 0, bytes.length);
fout.flush();
fout.close();
addMessages("GRP_INFO", fileName + " recieved from " + sender);
} catch (Exception e) {
e.printStackTrace();
}
}
private void addMessages(String user, String msg) {
// Adds Msg in panel Format to add to a chat window
Color textColor, bgColor;
FlowLayout layout = new FlowLayout();
JPanel row = new JPanel();
JLabel content = new JLabel(msg);
JLabel sender = new JLabel(user + " ");
JLabel time = new JLabel(getTime()); // Change to Actual Time
JPanel message = new RoundedPanel();
if (user.equals("GRP_INFO")) {
time.setVisible(false);
sender.setVisible(false);
layout.setAlignment(FlowLayout.CENTER);
textColor = new Color(255, 255, 255);
bgColor = new Color(110, 103, 103);
} else if (user.equals(Client.CURRENT_USER)) {
layout.setAlignment(FlowLayout.RIGHT);
textColor = new Color(255, 255, 255);
bgColor = new Color(0, 132, 255);
} else {
layout.setAlignment(FlowLayout.LEFT);
textColor = new Color(0, 0, 0);
bgColor = new Color(197, 197, 197);
}
row.setLayout(layout);
message.setLayout(new BoxLayout(message, BoxLayout.Y_AXIS));
sender.setFont(new Font("Helvitica", Font.BOLD, 11));
content.setFont(new Font("Helvitica", Font.PLAIN, 12));
time.setFont(new Font("Helvitica", Font.PLAIN, 10));
message.setBorder(new EmptyBorder(10, 10, 10, 10));
message.setBackground(bgColor);
sender.setForeground(textColor);
content.setForeground(textColor);
time.setForeground(textColor);
message.add(sender);
message.add(content);
message.add(time);
row.add(message);
chat.add(row, BorderLayout.NORTH); // Adds msg to chat layout
// chat.revalidate();
JPanel newChat = new JPanel();
newChat.setLayout(new BorderLayout());
chat.add(newChat, BorderLayout.CENTER);
chat = newChat;
chat.revalidate();
JScrollBar vertical = scrollPane.getVerticalScrollBar();
vertical.setValue(vertical.getMaximum());
JScrollBar vertica = scrollPane.getVerticalScrollBar();
vertical.setValue(vertica.getMaximum());
}
private String getTime() {
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm a");
return formatter.format(date);
}
public static void main(String[] args) {
// System.out.println("Start");
while (!Client.isSetupDone) {
System.out.print("");
}
// Wait till u get all info
Client client = new Client();
try {
client.clientSocket = new Socket(IP_ADDRESS_STRING, PORT);
DataInputStream din = new DataInputStream(client.clientSocket.getInputStream());
String groupName = din.readUTF();
client.groupName.setText(groupName);
DataOutputStream dout = new DataOutputStream(client.clientSocket.getOutputStream());
// Verification
String request = din.readUTF();
if (request.startsWith("RequestSecretText")) {
dout.writeUTF(enc.encrypt(Client.PASSWORD, Client.PASSWORD));
} else {
try {
String str = dec.decrypt(request, Client.PASSWORD);
if (!str.equals(Client.PASSWORD)) {
JOptionPane.showMessageDialog(client, "You Have entred Wrong Password", "Invalid Password",
JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
} catch (IllegalBlockSizeException | BadPaddingException e) {
client.dispose();
JOptionPane.showMessageDialog(client, "You Have entred Wrong Password", "Invalid Password",
JOptionPane.ERROR_MESSAGE);
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
new ClientVideoStreamThread().start();
new ClientAudioStreamThread().start();
dout.writeUTF("GRP_INFO" + ":::" + Client.CURRENT_USER + " joined the Chat.");
while (true) {
String response = din.readUTF();
String[] str = response.split(":::");
if (str[0].equals("FILE_TRANS")) {
client.handleFileTransfer(str[1], str[2], str[3], din);
} else if (str[0].equals("GRP_INFO"))
client.addMessages(str[0], str[1]);
else
client.addMessages(str[0], Client.dec.decrypt(str[1], Client.PASSWORD));
}
} catch (java.net.ConnectException e) {
client.groupName.setText("FAILED !");
JOptionPane.showMessageDialog(client, "Server doesn't exist : Invalid IP Address", "Server Not Found",
JOptionPane.ERROR_MESSAGE);
System.exit(0);
} catch (java.io.EOFException e) {
System.out.println("Ended");
} catch (Exception e) {
e.printStackTrace();
}
}
}
class ClientVideoStreamThread extends Thread {
Socket videoSocket;
public void run() {
try {
videoSocket = new Socket(Client.IP_ADDRESS_STRING, Client.PORT + 1);
Client.videoSocket = videoSocket;
JFrame videoFrame = Client.videoFrame;
ImageIcon ic;
JLabel videoFeed = new JLabel();
// videoFrame.setLayout(null);
videoFrame.setTitle("Client :" + Client.CURRENT_USER);
videoFrame.add(videoFeed);
videoFrame.setVisible(false);
videoFrame.setSize(Client.VIDEO_HEIGHT, Client.VIDEO_WIDTH);
videoFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
videoFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
videoFrame.setVisible(false);
}
});
while (true) {
ObjectInputStream oin = new ObjectInputStream((videoSocket.getInputStream()));
ic = (ImageIcon) oin.readObject();
videoFeed.setIcon(ic);
if (!videoFrame.isVisible())
videoFrame.setVisible(true);
if (ic != null && ic.getDescription() != null && ic.getDescription().equals("END_VIDEO")) {
videoFrame.setVisible(false);
}
}
} catch (java.io.EOFException e) {
System.out.println("Ended");
} catch (Exception e) {
e.printStackTrace();
}
}
}
class VideoOutstreamThread extends Thread {
ImageIcon ic;
BufferedImage br;
ObjectOutputStream stream;
Webcam cam;
VideoOutstreamThread(ImageIcon ic, BufferedImage br, ObjectOutputStream stream, Webcam cam) {
this.ic = ic;
this.br = br;
this.stream = stream;
this.cam = cam;
}
public void run() {
try {
while (Client.runCam) {
br = cam.getImage();
ic = new ImageIcon(br);
stream.writeObject(ic);
stream.flush();
}
ic = new ImageIcon("images\\endVideo.png", "END_VIDEO");
stream.writeObject(ic);
stream.flush();
} catch (Exception e) {
e.printStackTrace();
}
cam.close();
}
}
class ClientAudioStreamThread extends Thread {
Socket audioSocket;
ObjectInputStream ois;
AudioFormat format;
DataLine.Info info;
SourceDataLine speakers;
byte[] data;
public void run() {
try {
audioSocket = new Socket(Client.IP_ADDRESS_STRING, Client.PORT + 2);
Client.audioSocket = audioSocket;
data = new byte[1024];
format = new AudioFormat(48000.0f, 16, 2, true, false);
info = new DataLine.Info(SourceDataLine.class, format);
data = new byte[1024];
speakers = (SourceDataLine) AudioSystem.getLine(info);
speakers.open(format);
speakers.start();
ois = new ObjectInputStream(audioSocket.getInputStream());
while (true) {
int dsize = ois.read(data);
if (dsize == 1024) {
speakers.write(data, 0, dsize);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
class AudioOutStreamThread extends Thread {
private ObjectOutputStream oos;
private AudioFormat format;
private DataLine.Info info;
private TargetDataLine microphone;
private byte[] data;
private int dsize;
AudioOutStreamThread() {
}
public void run() {
try {
// Audio Stuff
format = new AudioFormat(48000.0f, 16, 2, true, false);
microphone = AudioSystem.getTargetDataLine(format);
info = new DataLine.Info(TargetDataLine.class, format);
data = new byte[1024];
microphone = (TargetDataLine) AudioSystem.getLine(info);
microphone.open(format);
microphone.start();
oos = new ObjectOutputStream(Client.audioSocket.getOutputStream());
// read and send part
while (Client.runCam) {
dsize = microphone.read(data, 0, data.length);
oos.write(data, 0, dsize);
oos.reset();
}
System.out.println("[ Client ] : Attempting to stop ");
oos.write(data, 0, 512);
oos.flush();
} catch (Exception e) {
e.printStackTrace();
}
microphone.stop();
microphone.close();
}
}