summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordor <dor1_b@walla.com>2013-11-30 14:10:14 +0200
committerdor <dor1_b@walla.com>2013-11-30 14:10:14 +0200
commit666377971c25f19f4114632c1adc0ff7d5b17e99 (patch)
treee1f69568827b32a7eaac15de01cce78f124af88f /src
parentcc73f7814f82232ec09fb4849e28e8976ee6afae (diff)
Evolving the client
Diffstat (limited to 'src')
-rw-r--r--src/Client/ChatClient.java35
-rw-r--r--src/Client/ChatClientReader.java9
-rw-r--r--src/Client/ChatClientWriter.java32
3 files changed, 65 insertions, 11 deletions
diff --git a/src/Client/ChatClient.java b/src/Client/ChatClient.java
index 458c19d..f8b3a55 100644
--- a/src/Client/ChatClient.java
+++ b/src/Client/ChatClient.java
@@ -1,18 +1,45 @@
package Client;
import java.io.*;
import java.net.Socket;
-import java.util.*;
+
import Server.ChatServer;
public class ChatClient
{
+ String nick;
+ String realname;
+
+ /** returning the nick name */
+ public String getNick ()
+ {
+ return this.nick;
+ }
+ /** returning the real name */
+ public String getRealname ()
+ {
+ return this.realname;
+ }
+ /** changing the nick name */
+ public void setNick (String nick)
+ {
+ this.nick = nick;
+ }
+ /** changing the real name */
+ public void setRealname (String realname)
+ {
+ this.realname = realname;
+ }
public static void main(String[] args) throws IOException
{
- int port = ChatServer.portNum;
- String host = null;
+ int port = ChatServer.portNum; //FIXME: Need editable port.
+ String host = "192.168.1.22"; //FIXME: Need editable host.
Socket soc;
+ ChatClient client = new ChatClient();
+ client.setNick("dor");
+ client.setRealname("Dor bivas");
+
try
{
soc = new Socket(host, port);
@@ -23,7 +50,7 @@ public class ChatClient
}
ChatClientReader reader = new ChatClientReader(soc);
- ChatClientWriter writer = new ChatClientWriter(soc);
+ ChatClientWriter writer = new ChatClientWriter(soc,client);
reader.start();
writer.start();
diff --git a/src/Client/ChatClientReader.java b/src/Client/ChatClientReader.java
index b7b4ea1..64f92a0 100644
--- a/src/Client/ChatClientReader.java
+++ b/src/Client/ChatClientReader.java
@@ -6,9 +6,10 @@ import java.io.*;
public class ChatClientReader extends Thread
{
public static Scanner reader = new Scanner(System.in);
-
private Socket soc;
+
+
public ChatClientReader (Socket soc)
{
this.soc = soc;
@@ -26,6 +27,10 @@ public class ChatClientReader extends Thread
do {
line = input.readLine(); // FIXME: more then 1 line
+ if (line == null)
+ {
+ soc.close();
+ }
line = "[" + line + "]";
System.out.println("");
System.out.println(line);
@@ -36,6 +41,8 @@ public class ChatClientReader extends Thread
System.err.println(e);
return;
}
+
+
}
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) {}