summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDor Bivas <dor1_b@walla.com>2013-12-04 13:25:58 +0200
committerDor Bivas <dor1_b@walla.com>2013-12-04 13:25:58 +0200
commit8a3de31a6337dfa0e0c77bdffe55419cadb22f80 (patch)
treee388edd85f19f5bbff1a7d9b3504529e33fd055b
parent5cf24366b9dc81a6e3f8f74c58e93b3b7005b361 (diff)
sent massege to server
-rw-r--r--src/Client/ChatClientWriter.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/Client/ChatClientWriter.java b/src/Client/ChatClientWriter.java
index 8e16655..7bce6dd 100644
--- a/src/Client/ChatClientWriter.java
+++ b/src/Client/ChatClientWriter.java
@@ -2,12 +2,14 @@ package Client;
import java.io.*;
import java.net.Socket;
import java.util.*;
+import java.util.concurrent.LinkedBlockingQueue;
public class ChatClientWriter extends Thread
{
private ChatClient client;
private Socket soc;
private BufferedWriter output;
+ private LinkedBlockingQueue<String> queue;
public static Scanner reader = new Scanner(System.in);
@@ -17,6 +19,19 @@ public class ChatClientWriter extends Thread
{
this.soc = soc;
this.client = client;
+ this.queue = new LinkedBlockingQueue<String>();
+ }
+
+ public void sendLine (String line)
+ {
+ try
+ {
+ this.queue.put(line);
+ } catch (InterruptedException e)
+
+ {
+ System.err.println("input line is null: " + e);
+ }
}
/** writing the line and making sure the package will be pushed on the stream
@@ -52,7 +67,14 @@ public class ChatClientWriter extends Thread
while (true)
{
System.out.print("Write here: > ");
- line = reader.nextLine();
+ try
+ {
+ line = this.queue.take();
+ } catch (InterruptedException e){line = "";}
+
+
+ System.out.println(line);
+
this.output.write(line, 0, line.length());
this.output.newLine();
this.output.flush();