-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathConnectionThread.java
More file actions
50 lines (43 loc) · 1.55 KB
/
ConnectionThread.java
File metadata and controls
50 lines (43 loc) · 1.55 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ConsoleApp;
import java.io.IOException;
import java.net.Socket;
import javaChat.Connection;
/**
*
* @author GL552JX
*/
public class ConnectionThread extends Thread {
private Socket client;
private Connection connection;
public ConnectionThread(Socket newClient) throws IOException{
this.client = newClient;
connection = new Connection(client);
}
public void run(){
try {
connection.startChat(" Start The Chat ");
System.out.println(" ---------------- ");
System.out.println(" new cilent connected ");
System.out.println(" client information ");
System.out.println(connection.getClientInformation());
String inputan;
String message;
while((inputan = connection.readStream()) != null && inputan.equals("Quit")){
message = "Client " + connection.getIpClient() + "Said : " + inputan;
System.out.println(message);
connection.sendToAll(message);
}
message = "Client from IP : " + connection.getIpClient() + "Quit the chat room";
System.out.println(message);
connection.sendToAll(message);
connection.disconnect();
} catch (Exception e) {
System.out.println("Error");
}
}
}