-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatClientThread.java
More file actions
45 lines (42 loc) · 1.07 KB
/
ChatClientThread.java
File metadata and controls
45 lines (42 loc) · 1.07 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
package clientServer;
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 getting input stream: " + ioe);
client.stop();
}
}
public void close()
{ try
{ if (streamIn != null) streamIn.close();
}
catch(IOException ioe)
{ System.out.println("Error closing input stream: " + ioe);
}
}
public void run()
{ while (true)
{ try
{ client.handle(streamIn.readUTF());
}
catch(IOException ioe)
{ System.out.println("Listening error: " + ioe.getMessage());
client.stop();
}
}
}
}