From b4dbd2cfa724476162fa6d35941a5d7cdc9c9524 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 18 Feb 2019 08:10:10 -0500 Subject: Adds all assignments not previously in a git repo --- CS2452/chatThreaded/ChatClient.java | 40 +++++++++++++++++++++++++++++++++++++ CS2452/chatThreaded/ChatServer.java | 27 +++++++++++++++++++++++++ CS2452/chatThreaded/T1.java | 33 ++++++++++++++++++++++++++++++ CS2452/chatThreaded/T2.java | 32 +++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 CS2452/chatThreaded/ChatClient.java create mode 100644 CS2452/chatThreaded/ChatServer.java create mode 100644 CS2452/chatThreaded/T1.java create mode 100644 CS2452/chatThreaded/T2.java (limited to 'CS2452/chatThreaded') diff --git a/CS2452/chatThreaded/ChatClient.java b/CS2452/chatThreaded/ChatClient.java new file mode 100644 index 0000000..1822240 --- /dev/null +++ b/CS2452/chatThreaded/ChatClient.java @@ -0,0 +1,40 @@ +import java.util.*; +import java.io.*; +import java.net.*; + + + +class ChatClient +{ + public static void main(String[] args) + { + Socket s; + InetAddress address = null; + int port = 0; + + + + try + { + address = InetAddress.getByName(args[0]); + port = Integer.parseInt(args[1]); + }catch (UnknownHostException ex){ + ex.printStackTrace(); + } + + try + { + s = new Socket(address, port); + + T1 screenWriter = new T1(s); + T2 socketWriter = new T2(s); + screenWriter.start(); + socketWriter.start(); + + } + catch(Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/CS2452/chatThreaded/ChatServer.java b/CS2452/chatThreaded/ChatServer.java new file mode 100644 index 0000000..67608d1 --- /dev/null +++ b/CS2452/chatThreaded/ChatServer.java @@ -0,0 +1,27 @@ +import java.util.*; +import java.io.*; +import java.net.*; + +class ChatServer +{ + public static void main(String[] args) + { + ServerSocket ss; + Socket s; + + try + { + ss = new ServerSocket(2452); + s = ss.accept(); + + T1 screenWriter = new T1(s); + T2 socketWriter = new T2(s); + screenWriter.start(); + socketWriter.start(); + } + catch(Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/CS2452/chatThreaded/T1.java b/CS2452/chatThreaded/T1.java new file mode 100644 index 0000000..6fd8e06 --- /dev/null +++ b/CS2452/chatThreaded/T1.java @@ -0,0 +1,33 @@ +import java.util.*; +import java.io.*; +import java.net.*; + + +class T1 extends Thread +{ + Socket s; + + public T1(Socket socket) + { + s = socket; + } + public void run() + { + BufferedReader tr = new BufferedReader(new InputStreamReader(System.in)); + + try + { + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())); + + while(true) + { + bw.write(tr.readLine()); + bw.newLine(); + bw.flush(); + } + }catch(Exception e){ + e.printStackTrace(); + } + } +} + diff --git a/CS2452/chatThreaded/T2.java b/CS2452/chatThreaded/T2.java new file mode 100644 index 0000000..470c917 --- /dev/null +++ b/CS2452/chatThreaded/T2.java @@ -0,0 +1,32 @@ + +import java.util.*; +import java.io.*; +import java.net.*; + + +class T2 extends Thread +{ + Socket s; + public T2(Socket socket) + { + s = socket; + } + public void run() + { + + try + { + + BufferedReader bw = new BufferedReader( new InputStreamReader(s.getInputStream())); + String str = "Connected"; + do + { + System.out.printf("%s\n", str); + str = bw.readLine(); + }while (str != null); + }catch(Exception e){ + e.printStackTrace(); + } + } +} + -- cgit v1.1