summaryrefslogtreecommitdiff
path: root/src/ChatClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ChatClient.java')
-rw-r--r--src/ChatClient.java74
1 files changed, 58 insertions, 16 deletions
diff --git a/src/ChatClient.java b/src/ChatClient.java
index 77abe11..620622a 100644
--- a/src/ChatClient.java
+++ b/src/ChatClient.java
@@ -1,28 +1,70 @@
import java.io.*;
import java.net.Socket;
import java.util.*;
-public class ChatClient
+
+public class ChatClient
{
- public static Scanner reader = new Scanner (System.in);
+ public static Scanner reader = new Scanner(System.in);
+
public static void main(String[] args) throws IOException
{
- String phrase = "Hay";
- int port = 10000;
+ String phrase;
+ System.out.println("Enter you phrase");
+ phrase = reader.nextLine();
+ int port = ChatServer.portNum;
String host = null;
- Socket Soc = new Socket( host, port);
- OutputStreamWriter outTemp = new OutputStreamWriter (Soc.getOutputStream());
- BufferedWriter output = new BufferedWriter (outTemp);
- InputStreamReader inputTemp = new InputStreamReader (Soc.getInputStream());
- BufferedReader input = new BufferedReader (inputTemp);
- phrase = input.readLine(); //FIXME: more then 1 line
- phrase = "[" + phrase + "]";
- System.out.println(phrase);
- output.write(phrase,0,phrase.length());
- output.newLine();
- output.flush();
- Soc.close();
+ Socket Soc;
+ OutputStreamWriter outTemp;
+ try
+ {
+ Soc = new Socket(host, port);
+ } catch (IOException e)
+ {
+ System.err.println("Error connecting to host " + host + ", port " + port + ": " + e);
+ return;
+ }
+ try
+ {
+ outTemp = new OutputStreamWriter(Soc.getOutputStream());
+ } catch (IOException e)
+ {
+ System.err.println("getOutputStream failed (should not have happened): " + e);
+ Soc.close();
+ return;
+ }
+ BufferedWriter output = new BufferedWriter(outTemp);
+ InputStreamReader inputTemp = new InputStreamReader(Soc.getInputStream());
+ BufferedReader input = new BufferedReader(inputTemp);
+ while (true)
+ {
+
+
+ output.write(phrase, 0, phrase.length());
+ output.newLine();
+ output.flush();
+ phrase = input.readLine(); // FIXME: more then 1 line
+ phrase = "[" + phrase + "]";
+ System.out.println(phrase);
+
+ }
+ Soc.close();
}
}
+class ConsoleReader extends Thread
+{
+ Socket Soc;
+
+ void setSoc(Socket Soc)
+ {
+ this.Soc = Soc;
+ }
+
+ public void run()
+ {
+
+ }
+
+} \ No newline at end of file