diff options
Diffstat (limited to 'src/Client')
-rw-r--r-- | src/Client/ChatClient.java | 36 | ||||
-rw-r--r-- | src/Client/ChatClientReader.java | 42 | ||||
-rw-r--r-- | src/Client/ChatClientWriter.java | 40 | ||||
-rw-r--r-- | src/Client/SwingTest.java | 30 |
4 files changed, 148 insertions, 0 deletions
diff --git a/src/Client/ChatClient.java b/src/Client/ChatClient.java new file mode 100644 index 0000000..150be9e --- /dev/null +++ b/src/Client/ChatClient.java @@ -0,0 +1,36 @@ +package Client;
+import java.io.*;
+import java.net.Socket;
+import java.util.*;
+
+import Server.ChatServer;
+
+public class ChatClient
+{
+
+ public static void main(String[] args) throws IOException
+ {
+ int port = ChatServer.portNum;
+ String host = null;
+ Socket Soc;
+ try
+ {
+ Soc = new Socket(host, port);
+ } catch (IOException e)
+ {
+ System.err.println("Failed connecting to server: " + host + ":" + port + " (" + e + ")");
+ return;
+ }
+
+ ChatClientReader reader = new ChatClientReader(Soc);
+ ChatClientWriter writer = new ChatClientWriter(Soc);
+
+ reader.start();
+ writer.start();
+
+ //Soc.close();
+ }
+
+}
+
+
diff --git a/src/Client/ChatClientReader.java b/src/Client/ChatClientReader.java new file mode 100644 index 0000000..8a495a5 --- /dev/null +++ b/src/Client/ChatClientReader.java @@ -0,0 +1,42 @@ +package Client;
+import java.net.Socket;
+import java.util.*;
+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;
+ }
+
+ public void run()
+ {
+ try
+ {
+
+ String phrase;
+
+ InputStreamReader inputTemp = new InputStreamReader(this.Soc.getInputStream());
+ BufferedReader input = new BufferedReader(inputTemp);
+
+ do {
+ phrase = input.readLine(); // FIXME: more then 1 line
+ phrase = "[" + phrase + "]";
+ System.out.println("");
+ System.out.println(phrase);
+ } while (phrase != null);
+
+
+ } catch (IOException e) {
+ System.err.println(e);
+ return;
+ }
+
+ }
+
+}
\ No newline at end of file diff --git a/src/Client/ChatClientWriter.java b/src/Client/ChatClientWriter.java new file mode 100644 index 0000000..3405fd1 --- /dev/null +++ b/src/Client/ChatClientWriter.java @@ -0,0 +1,40 @@ +package Client;
+import java.io.*;
+import java.net.Socket;
+import java.util.*;
+
+public class ChatClientWriter extends Thread
+{
+ private Socket Soc;
+
+ public static Scanner reader = new Scanner(System.in);
+
+ public ChatClientWriter(Socket Soc)
+ {
+ this.Soc = Soc;
+ }
+
+ public void run()
+ {
+ try
+ {
+ OutputStreamWriter outTemp;
+ String phrase;
+
+ outTemp = new OutputStreamWriter(this.Soc.getOutputStream());
+ BufferedWriter output = new BufferedWriter(outTemp);
+
+ while (true)
+ {
+ System.out.print("Write here:> ");
+ phrase = reader.nextLine();
+ output.write(phrase, 0, phrase.length());
+ output.newLine();
+ output.flush();
+ }
+
+ } catch (IOException e) {}
+
+ }
+
+}
diff --git a/src/Client/SwingTest.java b/src/Client/SwingTest.java new file mode 100644 index 0000000..15d5fc0 --- /dev/null +++ b/src/Client/SwingTest.java @@ -0,0 +1,30 @@ +package Client;
+import java.awt.Color;
+import java.util.*;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+
+public class SwingTest extends JFrame
+{
+ public static Scanner reader = new Scanner(System.in);
+ public static void main(String args[])
+ {
+ new SwingTest();
+
+
+ }
+
+ SwingTest()
+ {
+
+ this.setIconImage(getIconImage());
+ this.setSize(500, 100);
+ System.out.println("Enter Your massge here :");
+ String st = reader.nextLine();
+ Color Red = new Color(ABORT);
+ JLabel Test = new JLabel(st);
+ add(Test);
+ this.setBackground(getForeground());
+ setVisible(true);
+ }
+}
|