-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatClientThread1.java
More file actions
73 lines (63 loc) · 1.62 KB
/
ChatClientThread1.java
File metadata and controls
73 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
72
73
package Flawless_Feedback;
//Source:
// Creating a simple Chat Client1/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 ChatClientThread1 extends Thread
{
private Socket socket = null;
private MainForm client1 = null;
private DataInputStream streamIn = null;
public ChatClientThread1(MainForm _client1, Socket _socket)
{
client1 = _client1;
socket = _socket;
open();
start();
}
public void open()
{
try
{
streamIn = new DataInputStream(socket.getInputStream());
}
catch (IOException ioe)
{
System.out.println("Error getting input stream: " + ioe);
//client1.stop();
client1.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
{
client1.handle(streamIn.readUTF());
}
catch (IOException ioe)
{
System.out.println("Listening error: " + ioe.getMessage());
//client1.stop();
client1.close();
}
}
}
}