-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathConnectionThread.java
More file actions
53 lines (44 loc) · 1.61 KB
/
ConnectionThread.java
File metadata and controls
53 lines (44 loc) · 1.61 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 ConsoleApp;
import java.io.IOException;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javaChat.Connection;
/**
*
* @author lailis
*/
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("Strat 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 ex) { System.out.println("ERROR");
}
}
}