-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChatClientThread.java
47 lines (41 loc) · 1.09 KB
/
ChatClientThread.java
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
import java.net.*;
import java.io.*;
public class ChatClientThread extends Thread{
private Socket socket = null;
private ChatClient client = null;
private DataInputStream streamIn = null;
public ChatClientThread(ChatClient _client, Socket _socket){
client = _client;
socket = _socket;
open();
start();
}
public void open(){
try{
streamIn = new DataInputStream(socket.getInputStream());
}
catch(IOException ioe){
System.out.println("Error al abrir input stream: " + ioe);
client.stop();
}
}
public void close(){
try{
if (streamIn != null) streamIn.close();
}
catch(IOException ioe){
System.out.println("Error al cerrar input stream: " + ioe);
}
}
public void run(){
while (true){
try{
client.handle(streamIn.readUTF());
}
catch(IOException ioe){
System.out.println("error: " + ioe.getMessage());
client.stop();
}
}
}
}