-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatClientThread2.java
More file actions
71 lines (63 loc) · 1.62 KB
/
ChatClientThread2.java
File metadata and controls
71 lines (63 loc) · 1.62 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package Flawless_Feedback;
//Source:
// Creating a simple Chat Client/Server Solution
// http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-client-server.html
import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;
public class ChatClientThread2 extends Thread
{
private Socket socket = null;
private ClientForm client2 = null;
private DataInputStream streamIn = null;
public ChatClientThread2(ClientForm _client2, Socket _socket)
{
client2 = _client2;
socket = _socket;
open();
start();
}
public void open()
{
try
{
streamIn = new DataInputStream(socket.getInputStream());
}
catch (IOException ioe)
{
System.out.println("Error getting input stream: " + ioe);
//client2.stop();
client2.close();
}
}
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
{
client2.handle(streamIn.readUTF());
}
catch (IOException ioe)
{
System.out.println("Listening error: " + ioe.getMessage());
//client2.stop();
client2.close();
}
}
}
}