summaryrefslogtreecommitdiff
path: root/src/ChatClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ChatClient.java')
-rw-r--r--src/ChatClient.java45
1 files changed, 12 insertions, 33 deletions
diff --git a/src/ChatClient.java b/src/ChatClient.java
index ea0eeb9..53a6e81 100644
--- a/src/ChatClient.java
+++ b/src/ChatClient.java
@@ -4,51 +4,30 @@ import java.util.*;
public class ChatClient
{
- public static Scanner reader = new Scanner(System.in);
public static void main(String[] args) throws IOException
{
- String phrase;
int port = ChatServer.portNum;
String host = null;
Socket Soc;
- OutputStreamWriter outTemp;
-
- Soc = new Socket(host, port);
- outTemp = new OutputStreamWriter(Soc.getOutputStream());
- BufferedWriter output = new BufferedWriter(outTemp);
- InputStreamReader inputTemp = new InputStreamReader(Soc.getInputStream());
- BufferedReader input = new BufferedReader(inputTemp);
- while (true)
+ try
{
- System.out.print("Write here:> ");
- phrase = reader.nextLine();
- 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 = 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();
}
}
-class ConsoleReader extends Thread
-{
- Socket Soc;
-
- void setSoc(Socket Soc)
- {
- this.Soc = Soc;
- }
-
- public void run()
- {
-
- }
-} \ No newline at end of file