From 666377971c25f19f4114632c1adc0ff7d5b17e99 Mon Sep 17 00:00:00 2001 From: dor Date: Sat, 30 Nov 2013 14:10:14 +0200 Subject: Evolving the client --- src/Client/ChatClientWriter.java | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/Client/ChatClientWriter.java') diff --git a/src/Client/ChatClientWriter.java b/src/Client/ChatClientWriter.java index ba35bf2..76ff03d 100644 --- a/src/Client/ChatClientWriter.java +++ b/src/Client/ChatClientWriter.java @@ -5,32 +5,52 @@ 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) + 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()); - BufferedWriter output = new BufferedWriter(outTemp); + 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(); - output.write(line, 0, line.length()); - output.newLine(); - output.flush(); + this.output.write(line, 0, line.length()); + this.output.newLine(); + this.output.flush(); } } catch (IOException e) {} -- cgit v1.2.3