-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathConnectionThread.java
More file actions
49 lines (43 loc) · 1.6 KB
/
ConnectionThread.java
File metadata and controls
49 lines (43 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
/*
* 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 Herica Bunga M (1301154572)
*/
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 the 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 from chat room ";
System.out.println(message);
connection.sendToAll(message);
connection.disconnect();
} catch (IOException e) {
System.out.println("Error");
}
}
}