-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathConnectionThread.java
More file actions
52 lines (43 loc) · 1.54 KB
/
ConnectionThread.java
File metadata and controls
52 lines (43 loc) · 1.54 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
/*
* 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 javaChat;
/**
*
* @author ASUS
*/
import java.io.IOException;
import java.net.Socket;
import javaChat.Connection;
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 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");
}
}
}