blob: 76ff03d8e5b0fbb4a03061797db7ecda32d75818 (
plain)
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
|
package Client;
import java.io.*;
import java.net.Socket;
import java.util.*;
public class ChatClientWriter extends Thread
{
private ChatClient client;
private Socket soc;
private BufferedWriter output;
public static Scanner reader = new Scanner(System.in);
public ChatClientWriter(Socket soc ,ChatClient client)
{
this.soc = soc;
this.client = client;
}
public void println(String line)
{
try
{
this.output.write(line, 0, line.length());
this.output.newLine();
this.output.flush();
} catch (IOException e) {System.err.print("failed to print line" + e);}
}
public void run()
{
try
{
OutputStreamWriter outTemp;
String line;
outTemp = new OutputStreamWriter(this.soc.getOutputStream());
this.output = new BufferedWriter(outTemp);
println("NICK " + client.getNick());
// 0: mode (nothing special). *: unused in RFC 2812, server name in RFC 1459
println("USER " + client.getNick() + " 0 * :" + client.getRealname());
while (true)
{
System.out.print("Write here: > ");
line = reader.nextLine();
this.output.write(line, 0, line.length());
this.output.newLine();
this.output.flush();
}
} catch (IOException e) {}
}
}
|