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/chat/ChatClient.java | 47 +++++++++++++++++++++++++++++++++++++++++++++ CS2452/chat/ChatServer.java | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 CS2452/chat/ChatClient.java create mode 100644 CS2452/chat/ChatServer.java (limited to 'CS2452/chat') diff --git a/CS2452/chat/ChatClient.java b/CS2452/chat/ChatClient.java new file mode 100644 index 0000000..816d097 --- /dev/null +++ b/CS2452/chat/ChatClient.java @@ -0,0 +1,47 @@ +import java.util.*; +import java.io.*; +import java.net.*; + +class ChatClient +{ + public static void main(String[] args) + { + Socket s; + BufferedReader br, tr; + BufferedWriter bw; + InetAddress address = null; + int port = 0; + + tr = new BufferedReader(new InputStreamReader(System.in)); + + try{ + address = InetAddress.getByName(args[0]); + port = Integer.parseInt(args[1]); + }catch (UnknownHostException ex) + { + ex.printStackTrace(); + } + + try + { + System.out.printf("Connecting...\n"); + s = new Socket(address, port); + + br = new BufferedReader(new InputStreamReader(s.getInputStream())); + + bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())); + System.out.printf("Client>"); + + while(true) + { + bw.write(tr.readLine()); + bw.newLine(); + bw.flush(); + System.out.printf("%s: %s\n%s>", "Server", br.readLine(), "Client"); + } + } catch (Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/CS2452/chat/ChatServer.java b/CS2452/chat/ChatServer.java new file mode 100644 index 0000000..3259611 --- /dev/null +++ b/CS2452/chat/ChatServer.java @@ -0,0 +1,44 @@ +import java.io.*; +import java.util.*; +import java.net.*; + +class ChatServer +{ + public static void main(String[] args) + { + ServerSocket ss; + Socket s; + BufferedReader br, tr; + BufferedWriter bw; + + tr = new BufferedReader(new InputStreamReader(System.in)); + + try + { + ss = new ServerSocket(2452); + + s = ss.accept(); + System.out.printf("Client connected...\n"); + + + br = new BufferedReader(new InputStreamReader(s.getInputStream())); + bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())); + + //String[] address = new String[2]; + //address[0] = InetAddress.toString(s.getAddress()); + //address[1] = InetAddress.toString(s.getLocalAddress()); + + while(true) + { + System.out.printf("%s: %s\n%s>", "Client", br.readLine(), "Server"); + bw.write(tr.readLine()); + bw.newLine(); + bw.flush(); + } + + }catch (Exception e) + { + e.printStackTrace(); + } + } +} -- cgit v1.1