-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathConnectionThread.java
More file actions
54 lines (44 loc) · 1.6 KB
/
ConnectionThread.java
File metadata and controls
54 lines (44 loc) · 1.6 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
/*
* 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 Console;
import java.io.IOException;
import java.net.Socket;
import javaChat.Connection;
import javaChat.Connection;
/**
*
* @author Alwi faisal
*/
public class ConnectionThread {
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 chat");
System.out.println("-----------------------");
System.out.println("new client 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 : " + e.getMessage());
}
}
}